@dxos/echo-memory 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/dist/lib/Fact.mjs +1 -0
- package/dist/lib/FactFeed.mjs +1 -0
- package/dist/lib/Graph.mjs +1 -0
- package/dist/lib/Hash.mjs +1 -0
- package/dist/lib/Mapping.mjs +1 -0
- package/dist/lib/MemoryError.mjs +1 -0
- package/dist/lib/MemoryQuery.mjs +1 -0
- package/dist/lib/MemoryService.mjs +1 -0
- package/dist/lib/Ontology.mjs +1 -0
- package/dist/lib/Pipeline.mjs +1 -0
- package/dist/lib/Predicate.mjs +1 -0
- package/dist/lib/Rdf.mjs +1 -0
- package/dist/lib/RdfStore.mjs +1 -0
- package/dist/lib/Sparql.mjs +1 -0
- package/dist/lib/Subscription.mjs +1 -0
- package/dist/lib/Trig.mjs +1 -0
- package/dist/lib/Vocab.mjs +1 -0
- package/dist/lib/Vocabularies.mjs +1 -0
- package/dist/lib/chunk-Fact.mjs +245 -0
- package/dist/lib/chunk-Fact.mjs.map +1 -0
- package/dist/lib/chunk-FactFeed.mjs +29 -0
- package/dist/lib/chunk-FactFeed.mjs.map +1 -0
- package/dist/lib/chunk-Graph.mjs +147 -0
- package/dist/lib/chunk-Graph.mjs.map +1 -0
- package/dist/lib/chunk-Hash.mjs +16 -0
- package/dist/lib/chunk-Hash.mjs.map +1 -0
- package/dist/lib/chunk-Mapping.mjs +226 -0
- package/dist/lib/chunk-Mapping.mjs.map +1 -0
- package/dist/lib/chunk-MemoryError.mjs +10 -0
- package/dist/lib/chunk-MemoryError.mjs.map +1 -0
- package/dist/lib/chunk-MemoryQuery.mjs +99 -0
- package/dist/lib/chunk-MemoryQuery.mjs.map +1 -0
- package/dist/lib/chunk-MemoryService.mjs +31 -0
- package/dist/lib/chunk-MemoryService.mjs.map +1 -0
- package/dist/lib/chunk-Ontology.mjs +529 -0
- package/dist/lib/chunk-Ontology.mjs.map +1 -0
- package/dist/lib/chunk-Pipeline.mjs +84 -0
- package/dist/lib/chunk-Pipeline.mjs.map +1 -0
- package/dist/lib/chunk-Predicate.mjs +66 -0
- package/dist/lib/chunk-Predicate.mjs.map +1 -0
- package/dist/lib/chunk-Rdf.mjs +120 -0
- package/dist/lib/chunk-Rdf.mjs.map +1 -0
- package/dist/lib/chunk-RdfStore.mjs +60 -0
- package/dist/lib/chunk-RdfStore.mjs.map +1 -0
- package/dist/lib/chunk-Sparql.mjs +153 -0
- package/dist/lib/chunk-Sparql.mjs.map +1 -0
- package/dist/lib/chunk-Subscription.mjs +44 -0
- package/dist/lib/chunk-Subscription.mjs.map +1 -0
- package/dist/lib/chunk-Trig.mjs +106 -0
- package/dist/lib/chunk-Trig.mjs.map +1 -0
- package/dist/lib/chunk-Vocab.mjs +164 -0
- package/dist/lib/chunk-Vocab.mjs.map +1 -0
- package/dist/lib/chunk-Vocabularies.mjs +343 -0
- package/dist/lib/chunk-Vocabularies.mjs.map +1 -0
- package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
- package/dist/lib/index.mjs +19 -0
- package/dist/types/src/Fact.d.ts +339 -0
- package/dist/types/src/Fact.d.ts.map +1 -0
- package/dist/types/src/Fact.test.d.ts +2 -0
- package/dist/types/src/Fact.test.d.ts.map +1 -0
- package/dist/types/src/FactFeed.d.ts +11 -0
- package/dist/types/src/FactFeed.d.ts.map +1 -0
- package/dist/types/src/FactFeed.test.d.ts +2 -0
- package/dist/types/src/FactFeed.test.d.ts.map +1 -0
- package/dist/types/src/Graph.d.ts +31 -0
- package/dist/types/src/Graph.d.ts.map +1 -0
- package/dist/types/src/Graph.test.d.ts +2 -0
- package/dist/types/src/Graph.test.d.ts.map +1 -0
- package/dist/types/src/Hash.d.ts +3 -0
- package/dist/types/src/Hash.d.ts.map +1 -0
- package/dist/types/src/Mapping.d.ts +18 -0
- package/dist/types/src/Mapping.d.ts.map +1 -0
- package/dist/types/src/Mapping.test.d.ts +2 -0
- package/dist/types/src/Mapping.test.d.ts.map +1 -0
- package/dist/types/src/MemoryError.d.ts +33 -0
- package/dist/types/src/MemoryError.d.ts.map +1 -0
- package/dist/types/src/MemoryQuery.d.ts +136 -0
- package/dist/types/src/MemoryQuery.d.ts.map +1 -0
- package/dist/types/src/MemoryQuery.test.d.ts +2 -0
- package/dist/types/src/MemoryQuery.test.d.ts.map +1 -0
- package/dist/types/src/MemoryService.d.ts +72 -0
- package/dist/types/src/MemoryService.d.ts.map +1 -0
- package/dist/types/src/Ontology.d.ts +115 -0
- package/dist/types/src/Ontology.d.ts.map +1 -0
- package/dist/types/src/Ontology.test.d.ts +2 -0
- package/dist/types/src/Ontology.test.d.ts.map +1 -0
- package/dist/types/src/Pipeline.d.ts +103 -0
- package/dist/types/src/Pipeline.d.ts.map +1 -0
- package/dist/types/src/Predicate.d.ts +17 -0
- package/dist/types/src/Predicate.d.ts.map +1 -0
- package/dist/types/src/Predicate.test.d.ts +2 -0
- package/dist/types/src/Predicate.test.d.ts.map +1 -0
- package/dist/types/src/Rdf.d.ts +33 -0
- package/dist/types/src/Rdf.d.ts.map +1 -0
- package/dist/types/src/Rdf.test.d.ts +2 -0
- package/dist/types/src/Rdf.test.d.ts.map +1 -0
- package/dist/types/src/RdfStore.d.ts +471 -0
- package/dist/types/src/RdfStore.d.ts.map +1 -0
- package/dist/types/src/Sparql.d.ts +58 -0
- package/dist/types/src/Sparql.d.ts.map +1 -0
- package/dist/types/src/Sparql.test.d.ts +2 -0
- package/dist/types/src/Sparql.test.d.ts.map +1 -0
- package/dist/types/src/Subscription.d.ts +100 -0
- package/dist/types/src/Subscription.d.ts.map +1 -0
- package/dist/types/src/Trig.d.ts +8 -0
- package/dist/types/src/Trig.d.ts.map +1 -0
- package/dist/types/src/Trig.test.d.ts +2 -0
- package/dist/types/src/Trig.test.d.ts.map +1 -0
- package/dist/types/src/Vocab.d.ts +90 -0
- package/dist/types/src/Vocab.d.ts.map +1 -0
- package/dist/types/src/Vocabularies.d.ts +45 -0
- package/dist/types/src/Vocabularies.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +19 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +133 -3
- package/src/Fact.test.ts +74 -0
- package/src/Fact.ts +269 -0
- package/src/FactFeed.test.ts +40 -0
- package/src/FactFeed.ts +38 -0
- package/src/Graph.test.ts +106 -0
- package/src/Graph.ts +158 -0
- package/src/Hash.ts +15 -0
- package/src/Mapping.test.ts +197 -0
- package/src/Mapping.ts +320 -0
- package/src/MemoryError.ts +10 -0
- package/src/MemoryQuery.test.ts +67 -0
- package/src/MemoryQuery.ts +114 -0
- package/src/MemoryService.ts +89 -0
- package/src/Ontology.test.ts +94 -0
- package/src/Ontology.ts +571 -0
- package/src/Pipeline.ts +97 -0
- package/src/Predicate.test.ts +47 -0
- package/src/Predicate.ts +89 -0
- package/src/Rdf.test.ts +104 -0
- package/src/Rdf.ts +158 -0
- package/src/RdfStore.ts +111 -0
- package/src/Sparql.test.ts +72 -0
- package/src/Sparql.ts +237 -0
- package/src/Subscription.ts +47 -0
- package/src/Trig.test.ts +199 -0
- package/src/Trig.ts +170 -0
- package/src/Vocab.ts +134 -0
- package/src/Vocabularies.ts +204 -0
- package/src/index.ts +22 -0
- package/README.md +0 -3
package/src/Vocab.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as Fact from './Fact.ts';
|
|
8
|
+
import * as Rdf from './Rdf.ts';
|
|
9
|
+
|
|
10
|
+
const { namedNode, literal } = Rdf;
|
|
11
|
+
|
|
12
|
+
/** Semantic-index vocabulary (provenance and factuality predicates). */
|
|
13
|
+
export const SX = 'https://dxos.org/semantic#';
|
|
14
|
+
/** W3C PROV-O. */
|
|
15
|
+
export const PROV = 'http://www.w3.org/ns/prov#';
|
|
16
|
+
/** Entity IRI prefix. */
|
|
17
|
+
export const ENTITY = 'https://dxos.org/semantic/entity/';
|
|
18
|
+
/** Fact-node IRI prefix; a stored fact without an explicit graph is the graph of this IRI. */
|
|
19
|
+
export const FACT = 'https://dxos.org/semantic/fact/';
|
|
20
|
+
/** Named-graph IRI prefix for graphs the extractor names. */
|
|
21
|
+
export const GRAPH = 'https://dxos.org/semantic/graph/';
|
|
22
|
+
/** Ontology namespace: predicates and entity classes. */
|
|
23
|
+
export const DX = 'https://dxos.org/ontology/';
|
|
24
|
+
export const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
25
|
+
export const RDFS = 'http://www.w3.org/2000/01/rdf-schema#';
|
|
26
|
+
export const OWL = 'http://www.w3.org/2002/07/owl#';
|
|
27
|
+
export const XSD = 'http://www.w3.org/2001/XMLSchema#';
|
|
28
|
+
export const SKOS = 'http://www.w3.org/2004/02/skos/core#';
|
|
29
|
+
export const DCTERMS = 'http://purl.org/dc/terms/';
|
|
30
|
+
export const SCHEMA = 'https://schema.org/';
|
|
31
|
+
export const FOAF = 'http://xmlns.com/foaf/0.1/';
|
|
32
|
+
export const ORG = 'http://www.w3.org/ns/org#';
|
|
33
|
+
/** SIOC: online communities (posts, replies, channels, members). */
|
|
34
|
+
export const SIOC = 'http://rdfs.org/sioc/ns#';
|
|
35
|
+
/** Brain namespaces: each brain mints the predicates its extractors invent under its own IRI. */
|
|
36
|
+
export const BRAIN = 'https://dxos.org/semantic/brain/';
|
|
37
|
+
|
|
38
|
+
/** The graph holding the brain's predicate metadata (labels, descriptions, synonyms). */
|
|
39
|
+
export const ONTOLOGY_GRAPH = `${GRAPH}ontology`;
|
|
40
|
+
export const RDF_TYPE = `${RDF}type`;
|
|
41
|
+
export const RDFS_LABEL = `${RDFS}label`;
|
|
42
|
+
export const RDFS_COMMENT = `${RDFS}comment`;
|
|
43
|
+
export const RDFS_DOMAIN = `${RDFS}domain`;
|
|
44
|
+
export const RDFS_RANGE = `${RDFS}range`;
|
|
45
|
+
export const RDFS_IS_DEFINED_BY = `${RDFS}isDefinedBy`;
|
|
46
|
+
export const RDF_PROPERTY = `${RDF}Property`;
|
|
47
|
+
export const OWL_SAME_AS = `${OWL}sameAs`;
|
|
48
|
+
export const OWL_INVERSE_OF = `${OWL}inverseOf`;
|
|
49
|
+
export const OWL_EQUIVALENT_PROPERTY = `${OWL}equivalentProperty`;
|
|
50
|
+
export const OWL_DEPRECATED = `${OWL}deprecated`;
|
|
51
|
+
export const SKOS_ALT_LABEL = `${SKOS}altLabel`;
|
|
52
|
+
export const SKOS_EXAMPLE = `${SKOS}example`;
|
|
53
|
+
export const DCTERMS_CREATED = `${DCTERMS}created`;
|
|
54
|
+
export const DCTERMS_CREATOR = `${DCTERMS}creator`;
|
|
55
|
+
export const DCTERMS_IS_REPLACED_BY = `${DCTERMS}isReplacedBy`;
|
|
56
|
+
/** The version of the seed vocabulary a store holds, stated about the ontology graph. */
|
|
57
|
+
export const SX_SEED = `${SX}seed`;
|
|
58
|
+
/** The shorthand rules use for a predicate (`member_of`). */
|
|
59
|
+
export const SX_SHORTHAND = `${SX}shorthand`;
|
|
60
|
+
/** The class of every stored graph, so an unconstrained query can enumerate them. */
|
|
61
|
+
export const SX_GRAPH = `${SX}Graph`;
|
|
62
|
+
|
|
63
|
+
/** Named node in the `sx:` namespace. */
|
|
64
|
+
export const sx = (name: string) => namedNode(SX + name);
|
|
65
|
+
/** Named node in the `prov:` namespace. */
|
|
66
|
+
export const prov = (name: string) => namedNode(PROV + name);
|
|
67
|
+
/** IRI for an entity id. */
|
|
68
|
+
export const entityIri = (id: string) => namedNode(ENTITY + encodeURIComponent(id));
|
|
69
|
+
/** IRI for a fact id. */
|
|
70
|
+
export const factIri = (id: string) => namedNode(FACT + encodeURIComponent(id));
|
|
71
|
+
/** IRI for a named graph. */
|
|
72
|
+
export const graphIri = (name: string) => namedNode(GRAPH + encodeURIComponent(name));
|
|
73
|
+
/** Named node in the `dx:` namespace. */
|
|
74
|
+
export const dx = (name: string) => namedNode(DX + name);
|
|
75
|
+
|
|
76
|
+
/** The namespace a brain mints its predicates under. */
|
|
77
|
+
export const brainNamespace = (id: string): string => `${BRAIN}${encodeURIComponent(id)}/`;
|
|
78
|
+
|
|
79
|
+
/** The brain namespace an IRI was minted in, if it was minted in one. */
|
|
80
|
+
export const brainNamespaceOf = (iri: string): string | undefined => {
|
|
81
|
+
if (!iri.startsWith(BRAIN)) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
const end = iri.indexOf('/', BRAIN.length);
|
|
85
|
+
return end === -1 ? undefined : iri.slice(0, end + 1);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** The namespace of a brain that has no id of its own (a preview, a test). */
|
|
89
|
+
export const LOCAL_BRAIN = brainNamespace('local');
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* IRI of an entity the extractor named but could not resolve: local to the graph that mentions it, since a label
|
|
93
|
+
* alone does not say that two graphs mean the same thing.
|
|
94
|
+
*/
|
|
95
|
+
export const localEntityIri = (graph: string, id: string) => namedNode(`${graph}#${encodeURIComponent(id)}`);
|
|
96
|
+
|
|
97
|
+
/** The slug of a graph-local entity IRI (see {@link localEntityIri}), if it is one of `graph`'s. */
|
|
98
|
+
export const localEntityId = (graph: string, iri: string): string | undefined =>
|
|
99
|
+
iri.startsWith(`${graph}#`) ? decodeURIComponent(iri.slice(graph.length + 1)) : undefined;
|
|
100
|
+
|
|
101
|
+
/** The suffix every graph-local IRI of an entity slug ends with, whichever graph it is local to. */
|
|
102
|
+
export const localEntitySuffix = (id: string): string => `#${encodeURIComponent(id)}`;
|
|
103
|
+
|
|
104
|
+
/** True for an absolute IRI (`did:key:…`, `echo://…`, `mailto:…`); entity slugs never contain `:`. */
|
|
105
|
+
export const isIri = (value: string): boolean => /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
106
|
+
|
|
107
|
+
/** The node for an entity key: an absolute IRI as itself, a slug local to `graph` (under {@link ENTITY} when none). */
|
|
108
|
+
export const entityNode = (key: string, graph?: string) =>
|
|
109
|
+
isIri(key) ? namedNode(key) : graph !== undefined ? localEntityIri(graph, key) : entityIri(key);
|
|
110
|
+
|
|
111
|
+
/** Inverse of {@link entityNode}: the slug for an IRI local to `graph` or under {@link ENTITY}, any other IRI unchanged. */
|
|
112
|
+
export const entityKey = (iri: string, graph?: string): Fact.EntityKey =>
|
|
113
|
+
Fact.EntityKey.make(
|
|
114
|
+
(graph !== undefined ? localEntityId(graph, iri) : undefined) ??
|
|
115
|
+
(iri.startsWith(ENTITY) ? entityIdFromIri(iri) : iri),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
/** Plain string literal. */
|
|
119
|
+
export const str = (value: string) => literal(value);
|
|
120
|
+
/** Inverse of {@link entityIri}; throws on a non-entity IRI. */
|
|
121
|
+
export const entityIdFromIri = (iri: string) => {
|
|
122
|
+
if (!iri.startsWith(ENTITY)) {
|
|
123
|
+
throw new TypeError(`Expected entity IRI with prefix ${ENTITY}: ${iri}`);
|
|
124
|
+
}
|
|
125
|
+
return decodeURIComponent(iri.slice(ENTITY.length));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Inverse of {@link factIri}; throws on a non-fact IRI. */
|
|
129
|
+
export const factIdFromIri = (iri: string) => {
|
|
130
|
+
if (!iri.startsWith(FACT)) {
|
|
131
|
+
throw new TypeError(`Expected fact IRI with prefix ${FACT}: ${iri}`);
|
|
132
|
+
}
|
|
133
|
+
return decodeURIComponent(iri.slice(FACT.length));
|
|
134
|
+
};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as Ontology from './Ontology.ts';
|
|
8
|
+
import * as Vocab from './Vocab.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A published vocabulary's predicates, under that vocabulary's own IRIs, as a pack an ontology can be seeded with. The
|
|
12
|
+
* packs cover what conversations mostly state (people, organizations, work, discussion threads); each lists a curated
|
|
13
|
+
* subset, since every predicate shown to the extractor costs prompt tokens.
|
|
14
|
+
*/
|
|
15
|
+
export type Pack = {
|
|
16
|
+
/** Short id a configuration names the pack by (`schema`, `foaf`). */
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly label: string;
|
|
19
|
+
/** The vocabulary's namespace IRI; `rdfs:isDefinedBy` of every entry. */
|
|
20
|
+
readonly namespace: string;
|
|
21
|
+
readonly entries: ReadonlyArray<Ontology.Entry>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type Term = Omit<Ontology.Entry, 'iri' | 'name' | 'label' | 'definedBy'> & { readonly label?: string };
|
|
25
|
+
|
|
26
|
+
const pack = (id: string, label: string, namespace: string, terms: Record<string, [local: string, Term]>): Pack => ({
|
|
27
|
+
id,
|
|
28
|
+
label,
|
|
29
|
+
namespace,
|
|
30
|
+
entries: Object.entries(terms).map(([name, [local, term]]) =>
|
|
31
|
+
Ontology.entry(name, { ...term, iri: `${namespace}${local}`, definedBy: namespace }),
|
|
32
|
+
),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const schema = (name: string) => `${Vocab.SCHEMA}${name}`;
|
|
36
|
+
const foaf = (name: string) => `${Vocab.FOAF}${name}`;
|
|
37
|
+
const sioc = (name: string) => `${Vocab.SIOC}${name}`;
|
|
38
|
+
const org = (name: string) => `${Vocab.ORG}${name}`;
|
|
39
|
+
|
|
40
|
+
const PERSON = schema('Person');
|
|
41
|
+
const ORGANIZATION = schema('Organization');
|
|
42
|
+
const CREATIVE_WORK = schema('CreativeWork');
|
|
43
|
+
const EVENT = schema('Event');
|
|
44
|
+
|
|
45
|
+
/** schema.org beyond the seed: authorship, employment, organizational structure, events and software. */
|
|
46
|
+
export const SCHEMA: Pack = pack('schema', 'schema.org', Vocab.SCHEMA, {
|
|
47
|
+
has_author: ['author', { label: 'has author', range: PERSON, domain: CREATIVE_WORK }],
|
|
48
|
+
publisher: ['publisher', { synonyms: ['published by'], domain: CREATIVE_WORK }],
|
|
49
|
+
employee: [
|
|
50
|
+
'employee',
|
|
51
|
+
{ label: 'employs', synonyms: ['has employee', 'hired'], domain: ORGANIZATION, range: PERSON },
|
|
52
|
+
],
|
|
53
|
+
colleague: ['colleague', { label: 'colleague of', synonyms: ['works with', 'is colleague of'], domain: PERSON }],
|
|
54
|
+
parent_organization: [
|
|
55
|
+
'parentOrganization',
|
|
56
|
+
{
|
|
57
|
+
label: 'parent organization',
|
|
58
|
+
synonyms: ['is subsidiary of', 'owned by company'],
|
|
59
|
+
domain: ORGANIZATION,
|
|
60
|
+
range: ORGANIZATION,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
sub_organization: [
|
|
64
|
+
'subOrganization',
|
|
65
|
+
{
|
|
66
|
+
label: 'sub organization',
|
|
67
|
+
synonyms: ['has subsidiary', 'has division'],
|
|
68
|
+
domain: ORGANIZATION,
|
|
69
|
+
range: ORGANIZATION,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
affiliation: [
|
|
73
|
+
'affiliation',
|
|
74
|
+
{ label: 'affiliated with', synonyms: ['is affiliated with'], domain: PERSON, range: ORGANIZATION },
|
|
75
|
+
],
|
|
76
|
+
owns: ['owns', { synonyms: ['is owner of', 'possesses'] }],
|
|
77
|
+
sponsor: ['sponsor', { label: 'sponsored by', synonyms: ['funded by', 'backed by'] }],
|
|
78
|
+
attendee: ['attendee', { label: 'attended by', synonyms: ['has attendee'], domain: EVENT }],
|
|
79
|
+
organizer: ['organizer', { label: 'organized by', synonyms: ['hosted by', 'run by'], domain: EVENT }],
|
|
80
|
+
start_date: ['startDate', { label: 'starts on', synonyms: ['start date', 'begins on'] }],
|
|
81
|
+
end_date: ['endDate', { label: 'ends on', synonyms: ['end date', 'deadline'] }],
|
|
82
|
+
email: ['email', { label: 'has email', synonyms: ['email address'], domain: PERSON }],
|
|
83
|
+
url: ['url', { label: 'has url', synonyms: ['website'] }],
|
|
84
|
+
is_based_on: ['isBasedOn', { label: 'based on', synonyms: ['derived from', 'forked from'] }],
|
|
85
|
+
citation: ['citation', { label: 'cites work', synonyms: ['references paper'] }],
|
|
86
|
+
programming_language: [
|
|
87
|
+
'programmingLanguage',
|
|
88
|
+
{ label: 'written in', synonyms: ['programming language', 'implemented in'] },
|
|
89
|
+
],
|
|
90
|
+
software_version: ['softwareVersion', { label: 'at version', synonyms: ['software version', 'release'] }],
|
|
91
|
+
knows_language: ['knowsLanguage', { label: 'speaks', synonyms: ['knows language'], domain: PERSON }],
|
|
92
|
+
works_location: ['workLocation', { label: 'works in', synonyms: ['work location', 'office in'], domain: PERSON }],
|
|
93
|
+
award: ['award', { label: 'won award', synonyms: ['received award', 'awarded'] }],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/** FOAF: people, their interests, projects and what they made. */
|
|
97
|
+
export const FOAF: Pack = pack('foaf', 'FOAF', Vocab.FOAF, {
|
|
98
|
+
nick: ['nick', { label: 'nickname', synonyms: ['goes by', 'called', 'nicknamed'], domain: foaf('Person') }],
|
|
99
|
+
homepage: ['homepage', { synonyms: ['home page'] }],
|
|
100
|
+
interest: [
|
|
101
|
+
'topic_interest',
|
|
102
|
+
{ label: 'interested in', synonyms: ['likes', 'is into', 'cares about'], domain: foaf('Person') },
|
|
103
|
+
],
|
|
104
|
+
current_project: [
|
|
105
|
+
'currentProject',
|
|
106
|
+
{ label: 'current project', synonyms: ['is building', 'is working on project'], domain: foaf('Person') },
|
|
107
|
+
],
|
|
108
|
+
past_project: [
|
|
109
|
+
'pastProject',
|
|
110
|
+
{ label: 'past project', synonyms: ['used to work on', 'former project'], domain: foaf('Person') },
|
|
111
|
+
],
|
|
112
|
+
made: ['made', { synonyms: ['built', 'created', 'is maker of'] }],
|
|
113
|
+
based_near: ['based_near', { label: 'based near', synonyms: ['near', 'lives near'] }],
|
|
114
|
+
workplace_homepage: ['workplaceHomepage', { label: 'workplace homepage' }],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/** Dublin Core terms: documents, their subjects, versions and references. */
|
|
118
|
+
export const DCTERMS: Pack = pack('dcterms', 'Dublin Core', Vocab.DCTERMS, {
|
|
119
|
+
subject: ['subject', { label: 'has subject', synonyms: ['is on the topic of', 'categorized as'] }],
|
|
120
|
+
title: ['title', { label: 'titled', synonyms: ['has title', 'named'] }],
|
|
121
|
+
contributor: ['contributor', { label: 'contributed to by', synonyms: ['has contributor'] }],
|
|
122
|
+
references: ['references', { synonyms: ['points to', 'links'] }],
|
|
123
|
+
replaces: ['replaces', { synonyms: ['supersedes', 'succeeds'] }],
|
|
124
|
+
has_part: ['hasPart', { label: 'has part', synonyms: ['contains', 'includes'] }],
|
|
125
|
+
has_version: ['hasVersion', { label: 'has variant', synonyms: ['variant of', 'edition of'] }],
|
|
126
|
+
conforms_to: ['conformsTo', { label: 'conforms to', synonyms: ['complies with', 'implements spec'] }],
|
|
127
|
+
license: ['license', { label: 'licensed under', synonyms: ['license'] }],
|
|
128
|
+
language: ['language', { label: 'in language' }],
|
|
129
|
+
modified: ['modified', { label: 'modified on', synonyms: ['updated on', 'last changed'] }],
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/** W3C Organization Ontology: reporting lines, posts and units. */
|
|
133
|
+
export const ORG: Pack = pack('org', 'W3C Organization', Vocab.ORG, {
|
|
134
|
+
head_of: [
|
|
135
|
+
'headOf',
|
|
136
|
+
{ label: 'head of', synonyms: ['leads', 'runs', 'is head of', 'manages'], range: org('Organization') },
|
|
137
|
+
],
|
|
138
|
+
reports_to: ['reportsTo', { label: 'reports to', synonyms: ['managed by', 'works under'] }],
|
|
139
|
+
has_unit: ['hasUnit', { label: 'has unit', synonyms: ['has team', 'has department'] }],
|
|
140
|
+
unit_of: ['unitOf', { label: 'unit of', synonyms: ['team of', 'department of'] }],
|
|
141
|
+
has_site: ['hasSite', { label: 'has site', synonyms: ['has office', 'office at'] }],
|
|
142
|
+
purpose: ['purpose', { label: 'has purpose', synonyms: ['mission', 'aims to'] }],
|
|
143
|
+
resulted_from: ['resultedFrom', { label: 'resulted from', synonyms: ['formed by', 'came out of'] }],
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/** SIOC: online-community structure, so chat threads read as posts, replies and channels. */
|
|
147
|
+
export const SIOC: Pack = pack('sioc', 'SIOC', Vocab.SIOC, {
|
|
148
|
+
has_creator: ['has_creator', { label: 'posted by', synonyms: ['has creator', 'sent by'], domain: sioc('Post') }],
|
|
149
|
+
reply_of: [
|
|
150
|
+
'reply_of',
|
|
151
|
+
{ label: 'reply to', synonyms: ['replies to', 'responds to', 'answers'], domain: sioc('Post') },
|
|
152
|
+
],
|
|
153
|
+
has_container: ['has_container', { label: 'posted in', synonyms: ['in channel', 'in thread'], domain: sioc('Item') }],
|
|
154
|
+
container_of: ['container_of', { label: 'contains post', synonyms: ['channel of'] }],
|
|
155
|
+
topic: ['topic', { label: 'has topic', synonyms: ['discusses', 'is discussing'] }],
|
|
156
|
+
links_to: ['links_to', { label: 'links to', synonyms: ['shares link to', 'shared'] }],
|
|
157
|
+
addressed_to: ['addressed_to', { label: 'addressed to', synonyms: ['directed at', 'pings', 'tags'] }],
|
|
158
|
+
moderator_of: ['moderator_of', { label: 'moderator of', synonyms: ['moderates', 'admin of'] }],
|
|
159
|
+
subscriber_of: ['subscriber_of', { label: 'subscribed to', synonyms: ['follows channel', 'watches'] }],
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/** Every pack, in the order {@link compose} prefers them when two claim one surface form. */
|
|
163
|
+
export const ALL: ReadonlyArray<Pack> = [SCHEMA, FOAF, DCTERMS, ORG, SIOC];
|
|
164
|
+
|
|
165
|
+
/** The pack a configuration names, if any. */
|
|
166
|
+
export const get = (id: string): Pack | undefined => ALL.find((candidate) => candidate.id === id);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* An ontology seeded with these packs on top of `base` (the default seed). A pack predicate the ontology already
|
|
170
|
+
* defines, or whose surface form an earlier one claims, is left out, so packs compose in any combination.
|
|
171
|
+
*/
|
|
172
|
+
export const compose = (packs: ReadonlyArray<Pack>, base: Ontology.Ontology = Ontology.DEFAULT): Ontology.Ontology =>
|
|
173
|
+
base.include(packs.flatMap(({ entries }) => entries));
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The ontology extraction uses when the caller names none: the seed plus every pack, so facts land on
|
|
177
|
+
* published predicates (schema.org, FOAF, …) rather than freshly minted ones.
|
|
178
|
+
*/
|
|
179
|
+
export const DEFAULT: Ontology.Ontology = compose(ALL);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The packs a comma-separated list of ids names (`schema,foaf,sioc`; `all` for every pack; `none` for
|
|
183
|
+
* the bare seed).
|
|
184
|
+
* @throws Error naming an unknown id.
|
|
185
|
+
*/
|
|
186
|
+
export const parse = (ids: string): Pack[] => {
|
|
187
|
+
const names = ids
|
|
188
|
+
.split(',')
|
|
189
|
+
.map((id) => id.trim())
|
|
190
|
+
.filter((id) => id.length > 0);
|
|
191
|
+
if (names.includes('all')) {
|
|
192
|
+
return [...ALL];
|
|
193
|
+
}
|
|
194
|
+
if (names.includes('none')) {
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
return names.map((id) => {
|
|
198
|
+
const found = get(id);
|
|
199
|
+
if (!found) {
|
|
200
|
+
throw new Error(`Unknown vocabulary "${id}"; known: ${ALL.map((candidate) => candidate.id).join(', ')}, all.`);
|
|
201
|
+
}
|
|
202
|
+
return found;
|
|
203
|
+
});
|
|
204
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export * as Fact from './Fact.ts';
|
|
6
|
+
export * as FactFeed from './FactFeed.ts';
|
|
7
|
+
export * as Graph from './Graph.ts';
|
|
8
|
+
export * as Hash from './Hash.ts';
|
|
9
|
+
export * as Mapping from './Mapping.ts';
|
|
10
|
+
export * as MemoryError from './MemoryError.ts';
|
|
11
|
+
export * as MemoryQuery from './MemoryQuery.ts';
|
|
12
|
+
export * as MemoryService from './MemoryService.ts';
|
|
13
|
+
export * as Ontology from './Ontology.ts';
|
|
14
|
+
export * as Pipeline from './Pipeline.ts';
|
|
15
|
+
export * as Predicate from './Predicate.ts';
|
|
16
|
+
export * as Rdf from './Rdf.ts';
|
|
17
|
+
export * as RdfStore from './RdfStore.ts';
|
|
18
|
+
export * as Sparql from './Sparql.ts';
|
|
19
|
+
export * as Subscription from './Subscription.ts';
|
|
20
|
+
export * as Trig from './Trig.ts';
|
|
21
|
+
export * as Vocab from './Vocab.ts';
|
|
22
|
+
export * as Vocabularies from './Vocabularies.ts';
|
package/README.md
DELETED