Skip to content

Commit

Permalink
Fix #668
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Nov 2, 2024
1 parent c6fbf27 commit da6235c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
22 changes: 16 additions & 6 deletions src/sparnatural/generators/sparql/ClassBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import StartClassGroup from "../../components/builder-section/groupwrapper/crite
import { getSettings } from "../../settings/defaultSettings";
import ISparnaturalSpecification from "../../spec-providers/ISparnaturalSpecification";
import SparqlFactory from "./SparqlFactory";
import { RDFS } from '../../spec-providers/BaseRDFReader';
import { OWL } from '../../spec-providers/owl/OWLSpecificationProvider';

const factory = new DataFactory();

Expand Down Expand Up @@ -64,7 +66,7 @@ export default class ClassBuilder {
}

#buildClsTriple(){
// don't build the class triple if the entity does not hove type
// don't build the class triple if the entity does not have type
if(this.specProvider.getEntity(this.classGroup.getTypeSelected()).hasTypeCriteria()) {
var typePredicate;
if(getSettings().typePredicate){
Expand All @@ -73,11 +75,19 @@ export default class ClassBuilder {
typePredicate = factory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
}

this.classTriple = SparqlFactory.buildTypeTriple(
factory.variable(this.classGroup.getVarName()?.replace('?','')) ,
typePredicate,
factory.namedNode(this.classGroup.getTypeSelected())
)
// don't add the type if the range is rdfs:Resource or owl:Thing
if(
(this.classGroup.getTypeSelected() != RDFS.RESOURCE.value)
&&
(this.classGroup.getTypeSelected() != OWL.THING.value)
) {
this.classTriple = SparqlFactory.buildTypeTriple(
factory.variable(this.classGroup.getVarName()?.replace('?','')) ,
typePredicate,
factory.namedNode(this.classGroup.getTypeSelected())
)
}

}
}

Expand Down
5 changes: 2 additions & 3 deletions src/sparnatural/spec-providers/BaseRDFReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ export const RDFS = {
COMMENT: factory.namedNode(RDFS_NAMESPACE + "comment") as NamedNode,
DOMAIN: factory.namedNode(RDFS_NAMESPACE + "domain") as NamedNode,
RANGE: factory.namedNode(RDFS_NAMESPACE + "range") as NamedNode,
SUBPROPERTY_OF: factory.namedNode(
RDFS_NAMESPACE + "subPropertyOf"
) as NamedNode,
RESOURCE: factory.namedNode(RDFS_NAMESPACE + "Resource") as NamedNode,
SUBPROPERTY_OF: factory.namedNode(RDFS_NAMESPACE + "subPropertyOf") as NamedNode,
SUBCLASS_OF: factory.namedNode(RDFS_NAMESPACE + "subClassOf") as NamedNode,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ const factory = new DataFactory();

const OWL_NAMESPACE = "http://www.w3.org/2002/07/owl#";
export const OWL = {
EQUIVALENT_PROPERTY: factory.namedNode(
OWL_NAMESPACE + "equivalentProperty"
) as NamedNode,
EQUIVALENT_CLASS: factory.namedNode(
OWL_NAMESPACE + "equivalentClass"
) as NamedNode,
THING: factory.namedNode(OWL_NAMESPACE + "Thing") as NamedNode,
EQUIVALENT_PROPERTY: factory.namedNode(OWL_NAMESPACE + "equivalentProperty") as NamedNode,
EQUIVALENT_CLASS: factory.namedNode(OWL_NAMESPACE + "equivalentClass") as NamedNode,
UNION_OF: factory.namedNode(OWL_NAMESPACE + "unionOf") as NamedNode
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ISHACLSpecificationEntity from "./ISHACLSpecificationEntity";
import { RdfStore } from "rdf-stores";
import { Quad, Quad_Subject, Term } from "@rdfjs/types/data-model";
import { StoreModel } from "../StoreModel";
import { OWL } from "../owl/OWLSpecificationProvider";
import { StatisticsReader } from "../StatisticsReader";

const factory = new DataFactory();
Expand Down

0 comments on commit da6235c

Please sign in to comment.