@@ -7,31 +7,56 @@ type Space = Tables<"Space">;
77type PlatformAccount = Tables < "PlatformAccount" > ;
88
99// This is a temporary hack
10- const KnownSchemaEntities : Record < string , string [ ] > = {
11- Claim : [ "dgc" , "mira" ] ,
12- Evidence : [ "dgc" , "mira" ] ,
13- Question : [ "dgc" , "mira" ] ,
14- SourceDocument : [ "dgc" ] ,
15- describesActivity : [ "dgc" ] ,
16- observationStatement : [ "dgc" ] ,
17- observationOriginActivity : [ "dgc" ] ,
18- observationBase : [ "dgc" ] ,
19- sourceDocument : [ "dgc" ] ,
20- opposes : [ "dgc" ] ,
21- opposedBy : [ "dgc" ] ,
22- supports : [ "dgc" ] ,
23- supportedBy : [ "dgc" ] ,
24- addresses : [ "dgc" ] ,
25- addressedBy : [ "dgc" ] ,
26- Request : [ "mira" ] ,
27- Protocol : [ "mira" ] ,
28- follows : [ "mira" ] ,
29- grounds : [ "mira" ] ,
30- is_grounded_in : [ "mira" ] ,
31- request_for : [ "mira" ] ,
32- request_target : [ "mira" ] ,
10+ export const KnownSchemaEntities : Record < string , string [ ] > = {
11+ Claim : [ "dgc:Claim " , "mira:Claim " ] ,
12+ Evidence : [ "dgc:Evidence " , "mira:Evidence " ] ,
13+ Question : [ "dgc:Question " , "mira:Question " ] ,
14+ SourceDocument : [ "dgc:SourceDocument " ] ,
15+ describesActivity : [ "dgc:describesActivity " ] ,
16+ observationStatement : [ "dgc:observationStatement " ] ,
17+ observationOriginActivity : [ "dgc:observationOriginActivity " ] ,
18+ observationBase : [ "dgc:observationBase " ] ,
19+ sourceDocument : [ "dgc:sourceDocument " ] ,
20+ opposes : [ "dgc:opposes " ] ,
21+ opposedBy : [ "dgc:opposedBy " ] ,
22+ supports : [ "dgc:supports " ] ,
23+ supportedBy : [ "dgc:supportedBy " ] ,
24+ addresses : [ "dgc:addresses " ] ,
25+ addressedBy : [ "dgc:addressedBy " ] ,
26+ Request : [ "mira:Request " ] ,
27+ Protocol : [ "mira:Protocol " ] ,
28+ follows : [ "mira:follows " ] ,
29+ grounds : [ "mira:grounds " ] ,
30+ is_grounded_in : [ "mira:is_grounded_in " ] ,
31+ request_for : [ "mira:request_for " ] ,
32+ request_target : [ "mira:request_target " ] ,
3333} ;
3434
35+ const prefixes : Record < string , string > = {
36+ rdf : "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ,
37+ rdfs : "http://www.w3.org/2000/01/rdf-schema#" ,
38+ owl : "http://www.w3.org/2002/07/owl#" ,
39+ dc : "http://purl.org/dc/elements/1.1/" ,
40+ prov : "http://www.w3.org/ns/prov#" ,
41+ sioc : "http://rdfs.org/sioc/ns#" ,
42+ dgb : "https://discoursegraphs.com/schema/dg_base#" ,
43+ dgc : "https://discoursegraphs.com/schema/dg_core#" ,
44+ mira : "http://purl.org/mira-science/mira#" ,
45+ } ;
46+
47+ export const curieToIri = ( curie : string ) : string => {
48+ const [ prefix , name ] : string [ ] = curie . split ( ":" , 1 ) ;
49+ const iri = prefixes [ prefix || "" ] ;
50+ if ( iri === undefined ) {
51+ console . error ( "Unknown prefix" , prefix ) ;
52+ return curie ;
53+ }
54+ return iri + name ;
55+ } ;
56+
57+ export const KnownSchemaCuries = Object . values ( KnownSchemaEntities ) . flat ( ) ;
58+ export const KnownSchemaIris = KnownSchemaCuries . map ( curieToIri ) ;
59+
3560export const asJsonLD = ( {
3661 space,
3762 concept,
@@ -60,7 +85,9 @@ export const asJsonLD = ({
6085 let schemaUrl : string | string [ ] = concept . schema_id
6186 ? "sdata:" + concept . schema_id
6287 : concept . arity === 2
63- ? "RelationDef"
88+ ? ( concept . reference_content as Record < string , Json > ) . source !== undefined
89+ ? "RelationDef"
90+ : "AbstractRelationDef"
6491 : "NodeSchema" ;
6592
6693 let extraData : Record < string , string | Json > = { } ;
@@ -84,25 +111,30 @@ export const asJsonLD = ({
84111 if ( schema !== undefined ) {
85112 const knownSchemas = KnownSchemaEntities [ schema ?. name ?? "" ] ;
86113 if ( knownSchemas !== undefined ) {
87- schemaUrl = [
88- schemaUrl ,
89- ...knownSchemas . map ( ( s ) => `${ s } :${ schema . name } ` ) ,
90- ] ;
114+ schemaUrl = [ schemaUrl , ...knownSchemas ] ;
91115 }
92116 } else if ( concept . is_schema ) {
93117 const subClasses : Array < Json > = [ ] ;
94118 const knownSchemas = KnownSchemaEntities [ concept . name ] ;
95119 // in that case we can skip the base class
96120 if ( knownSchemas !== undefined ) {
97- subClasses . push ( ...knownSchemas . map ( ( s ) => ` ${ s } : ${ concept . name } ` ) ) ;
121+ subClasses . push ( ...knownSchemas ) ;
98122 }
99123 if ( concept . arity === 2 ) {
100- // Explicit punning
101- subClasses . push ( "dgb:RelationInstance" , {
102- "@type" : "owl:Restriction" ,
103- onProperty : "rdf:predicate" ,
104- hasValue : "sdata:" + concept . id ,
105- } ) ;
124+ // triple vs abstract def
125+ const abstractRelType = (
126+ concept . reference_content as Record < string , Json >
127+ ) . relation_type ;
128+ if ( typeof abstractRelType === "number" ) {
129+ subClasses . push ( "sdata:" + abstractRelType ) ;
130+ } else {
131+ // Explicit punning
132+ subClasses . push ( "dgb:RelationInstance" , {
133+ "@type" : "owl:Restriction" ,
134+ onProperty : "rdf:predicate" ,
135+ hasValue : "sdata:" + concept . id ,
136+ } ) ;
137+ }
106138 }
107139 if ( subClasses . length > 1 ) extraData [ "subClassOf" ] = subClasses ;
108140 else if ( subClasses . length === 1 ) extraData [ "subClassOf" ] = subClasses [ 0 ] ! ;
0 commit comments