@ -76,14 +76,21 @@ export class JsonLdContextBuilder {
return this . iriTypes [ rdfType ] as JsonLdContextBuilder ;
return this . iriTypes [ rdfType ] as JsonLdContextBuilder ;
}
}
addSubject ( iri : string , rdfType? : string , annotations? : Annotation [ ] ) {
private getRelevantBuilders ( rdfType? : string ) : JsonLdContextBuilder [ ] {
const relevantBuilder = this . getRelevantBuilder ( rdfType ) ;
const relevantBuilder = this . getRelevantBuilder ( rdfType ) ;
if ( ! relevantBuilder . iriAnnotations [ iri ] ) {
return relevantBuilder === this ? [ this ] : [ this , relevantBuilder ] ;
relevantBuilder . iriAnnotations [ iri ] = [ ] ;
}
}
if ( annotations && annotations . length > 0 ) {
addSubject ( iri : string , rdfType? : string , annotations? : Annotation [ ] ) {
relevantBuilder . iriAnnotations [ iri ] . push ( . . . annotations ) ;
const relevantBuilders = this . getRelevantBuilders ( rdfType ) ;
}
relevantBuilders . forEach ( ( relevantBuilder ) = > {
if ( ! relevantBuilder . iriAnnotations [ iri ] ) {
relevantBuilder . iriAnnotations [ iri ] = [ ] ;
}
if ( annotations && annotations . length > 0 ) {
relevantBuilder . iriAnnotations [ iri ] . push ( . . . annotations ) ;
}
} ) ;
}
}
addPredicate (
addPredicate (
@ -93,41 +100,30 @@ export class JsonLdContextBuilder {
rdfType? : string ,
rdfType? : string ,
annotations? : Annotation [ ] ,
annotations? : Annotation [ ] ,
) {
) {
const relevantBuilder = this . getRelevantBuilder ( rdfType ) ;
const relevantBuilders = this . getRelevantBuilders ( rdfType ) ;
relevantBuilder . addSubject ( iri , undefined , annotations ) ;
relevantBuilders . forEach ( ( relevantBuilder ) = > {
if ( ! relevantBuilder . iriTypes [ iri ] ) {
relevantBuilder . addSubject ( iri , undefined , annotations ) ;
relevantBuilder . iriTypes [ iri ] = expandedTermDefinition ;
if ( ! relevantBuilder . iriTypes [ iri ] ) {
if ( isContainer ) {
relevantBuilder . iriTypes [ iri ] = expandedTermDefinition ;
relevantBuilder . iriTypes [ iri ] [ "@isCollection" ] = true ;
if ( isContainer ) {
}
relevantBuilder . iriTypes [ iri ] [ "@isCollection" ] = true ;
} else {
}
const curDef = relevantBuilder . iriTypes [ iri ] ;
} else {
const newDef = expandedTermDefinition ;
const curDef = relevantBuilder . iriTypes [ iri ] ;
// TODO: if you reuse the same predicate with a different cardinality,
const newDef = expandedTermDefinition ;
// it will overwrite the past cardinality. Perhapse we might want to
if ( isContainer ) {
// split contexts in the various shapes.
curDef [ "@isCollection" ] = true ;
if ( isContainer ) {
}
curDef [ "@isCollection" ] = true ;
// If the old and new versions both have types
}
if ( curDef [ "@type" ] && newDef [ "@type" ] ) {
// If the old and new versions both have types
if ( curDef [ "@type" ] !== newDef [ "@type" ] ) {
if ( curDef [ "@type" ] && newDef [ "@type" ] ) {
console . warn (
if (
` You've specified that a specific field " ${ iri } " can have an object of multiple literal types ( ${ curDef [ "@type" ] } or ${ newDef [ "@type" ] } ). This is not expressable in JSON-LD context, and we will randomly select one type to use. ` ,
Array . isArray ( curDef [ "@type" ] ) &&
) ;
! ( curDef [ "@type" ] as string [ ] ) . includes ( newDef [ "@type" ] )
}
) {
curDef [ "@type" ] . push ( newDef [ "@type" ] ) ;
} else if (
typeof curDef [ "@type" ] === "string" &&
curDef [ "@type" ] !== newDef [ "@type" ]
) {
// The typings are incorrect. String arrays are allowed on @type
// see https://w3c.github.io/json-ld-syntax/#example-specifying-multiple-types-for-a-node
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
curDef [ "@type" ] = [ curDef [ "@type" ] , newDef [ "@type" ] ] ;
}
}
}
}
}
} ) ;
}
}
generateNames ( ) : Record < string , string > {
generateNames ( ) : Record < string , string > {