npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arche-api

v1.2.1

Published

Functions to access ARCHE API and convert rdf data.

Downloads

31

Readme

ARCHE API functions

Introduction

The npm package library ARCHEapi contains three functions that work with the ACDH/ARCHE API and processes metadata, about projects, from RDF N-Triples as String response to JSON objects.

Motivation

To access the ACDH/ARCHE API and use the data in web-applications the externalized functions provide better usability in creating dynamic webpages.

Installation

npm install arche-api

In JS:

const {ARCHEdownloadResourceIdM, ARCHEdownloadResourceIdM2, openFile, ARCHErdfQuery, ARCHEmatchJSON} = require("arche-api/src");

or

import {ARCHEdownloadResourceIdM, ARCHEdownloadResourceIdM2, openFile, ARCHErdfQuery, ARCHEmatchJSON} from "arche-api/src";

In HTML:

<script src="https://unpkg.com/[email protected]/lib/arche-api.min.js"></script>

Download function(s)

So far one download function was created using the node js node-fetch module (https://github.com/node-fetch/node-fetch). The function ARCHEdownloadResourceIdM() name stands for ARCHE = Archive, download = download, ResourceID = API parameter resourceID, M = /metadata. The funciton provides a text response and prints a statusCode, header and URL in console as well as possible errors.

The async function requires four arguments and provides a callback:

  • host: <string> Exp.: "https://arche.acdh.oeaw.ac.at/api"
  • resourceID: <string> Exp.: "108254"
  • format: <string> Exp.: "application/n-triples"
  • readMode: <string> Exp.: "relatives"
  • callback: <Function>

Starting from version 1.2.0 the arguments are passed as object options:

"options": {
  "host": "string",
  "resourceID": "string",
  "format": "string",
  "readMode": "string"
}

Returns a text (string) response as callback().

Usage:

const downloader = ARCHEapi.ARCHEdownloadResourceIdM;

downloader(options, (response) => {
  console.log(response);
})

RDF query function(s)

So far one RDF query function was created using the node js module N3 (https://github.com/rdfjs/N3.js). The function can handle text response data provided by the above download function. Name: ARCHErdfQuery(); The function works like other rdf queries and requries at least one <string> to search for. If null is provided it will return a result for null based on the search results provided by at least on <string>.

  • subject: <string> or null Exp.: "https://arche.acdh.oeaw.ac.at/api/108254" or null
  • predicate: <string> or null Exp.: "https://vocabs.acdh.oeaw.ac.at/schema#hasTitle" or null
  • objects: <string> or null Exp.: "some text" or null
  • data: <string> as Turtle, TriG, N-Triples, and N-Quads formats (More info: https://github.com/rdfjs/N3.js/#parsing)

Starting from version 1.2.0 the arguments are passed as object options:

"options": {
  "subject": "string" or null
  "predicate": "string" or null
  "objects": "string" or null
  "data": "string"
  "expiry": "integer" or null
}

Creates quads and returns a JSON object:

"result" : {
  "values": [
    "predicate1": {
      "subject": "subject",
      "prediate": "predicate",
      "object": "object",
      "lang": "language"
    },
    "predicate2": {
      "subject": "subject",
      "prediate": "predicate",
      "object": "object",
      "lang": "language"
    },
  ],
  "date": { "expiry": "date" }
}

Usage:

const query = ARCHEapi.ARCHErdfQuery;

const result = query(options, data);
console.log(result);

Matching and sorting

The N3 module can only handle one search request as described above and cannot handle multiple queries at once. This function takes two datasets and matches tham by subject id and returns subject id of dataset1 with matching predicate and object ids of dataset2. Name: ARCHEmatchJSON();

  • dataset1: <Object>
  • dataset2: <Object>

Returns and <Object>

Usage:

const match = ARCHEapi.ARCHEmatchJSON;

const result = match(dataset1, dataset2);
console.log(result);

Complete ARCHE Download example

const downloader = ARCHEapi.ARCHEdownloadResourceIdM;
const query = ARCHEapi.ARCHErdfQuery;
const match = ARCHEapi.ARCHEmatchJSON;

// declaring variables for downlaoding data
const host = "https://arche.acdh.oeaw.ac.at/api";
const format = "application/n-triples";
const resourceId = "108254";
const readMode = 'relatives';

downloader(host, resourceId, format, readMode, (rs) => {
    console.log(rs);
    // first query:
    let subject = null;
    let predicate = "https://vocabs.acdh.oeaw.ac.at/schema#isPartOf";
    let object = "https://arche.acdh.oeaw.ac.at/api/108254";
    let resources = query(subject, predicate, object, rs);  
    console.log(resources);
    // second query:
    let subject = null;
    let predicate = "https://vocabs.acdh.oeaw.ac.at/schema#hasTitle";
    let object = null;
    let titles = query(subject, predicate, object, rs);
    console.log(titles);
    // matching:
    let result = match(resources, titles);        
    console.log(result);
});

// new with version 1.2.0

const options = {
  "host" = "https://arche.acdh.oeaw.ac.at/api",
  "format" = "application/n-triples",
  "resourceId" = "108254",
  "readMode" = "relatives"
};

downloader(options, (rs) => {
    console.log(rs);
    // query:
    const options = {
      "subject" = "https://arche.acdh.oeaw.ac.at/api",
      "predicate" = "application/n-triples",
      "object" = "108254",
      "expiry" = 7
    };
    let resources = query(options, rs);  
    console.log(resources);
    // how to use the object
    var array = {
        "titles":[],
        "creators":[]
    };
    resources.value.forEach(function(rs) {
        var hasTitle = rs.hasTitle;
        var hasCreator = rs.hasCreator;
        if (hasTitle) {
            array.titles.push(hasTitle)
        }
        else if (hasCreator) {
            array.creators.push(hasCreator)
        }
    });     
    console.log(array);
});

License

MIT