Why doesn't the Jena validator give me warnings? - jena

In the following code, the ValidityReport is always valid; there is no inconsistency detected. I expect that it should give me a warning because I am giving a family name to a FOAF document. Why isn't an inconsistency detected?
Model model = ModelFactory.createDefaultModel();
OntModel m = ModelFactory.createOntologyModel();
m.read(FOAF.NS);
Resource persona = model.createResource("http://www.example.org/rdf#Persona", FOAF.Document);
persona.addProperty(FOAF.family_name, "18", XSDDatatype.XSDint);
InfModel infModel = ModelFactory.createRDFSModel(m, model);
ValidityReport validity = infModel.validate();
if (validity.isValid()) {
System.out.println("Valid!");
} else {
System.out.println("Conflicts");
for (Iterator<Report> in = validity.getReports(); in.hasNext();) {
System.out.println(" - " + in.next());
}
}

The instance data that you're creating is this:
#prefix ex: <http://www.example.org/rdf#> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Persona a foaf:Document ;
foaf:family_name "18"^^xsd:int .
There's a resource of type foaf:Document, and it has an xsd:int value for the the foaf:family_name property.
Your inference model uses an RDFS reasoner. The domain of foaf:family_name (which, by the way, is described as an archaic spelling of foaf:familyName) is foaf:Person, so ex:Persona can thus be inferred to be a foaf:Person, as we see if we write the inference model. There are a number of other types that ex:Persona is inferred to have as well:
ex:Persona a foaf:Document , foaf:Person , <http://www.w3.org/2000/01/rdf-schema#Resource> , <http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing> , foaf:Agent ;
foaf:family_name "18"^^xsd:int .
It's rather hard to have inconsistencies in an RDFS model, since you can't really say a whole lot. You can't declare disjoint classes, for instance, so there's no contradiction between something being a foaf:Document and a foaf:Person.
Even if you use an OWL reasoner, you'd still need to pinpoint some particular logical inconsistency. I don't know whether any of those types that ex:Persona has are disjoint, and if they're not (or if the reasoner can't infer that they are), you're not going to find an inconsistency.

Related

Not able to generate inference for propertyChainAxiom

I am using propertyChainAxiom to build one of the inference statements. I have defined a basic ontology which defines properties and statements as below :
ex:
:isParent rdf:type owl:ObjectProperty .
:Person1 :hasParent :Person2.
:Person2 :hasParent :Person3.
:hasGrandParent owl:propertyChainAxiom (:hasParent :hasParent) .
:Person1 :hasGrandParent ?o .
I have defined ontology and thesaurus in Ontotext GraphDB and have used the OWL2-horst ruleset.
The statement :Person1 :hasGrandParent doesn't seems to return Person3 as per inferred statement. Am I missing something here ?
As Damyan said, use OWL-RL.
Reposting his comment as answer, so this question doesn't appear again in [graphdb] answers:0

Extending XFeatureCall scope

This has been puzzling me for a while... I have done research, tried lots of things but failed miserably. The time has come to ask here.
My grammar has this rule to define types:
MyTypeDeclaration returns XExpression:
=>({MyTypeDeclaration} type=JvmTypeReference name=ValidID '(')
(params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)?
')' block=XBlockExpression
;
Of course, in the inferrer, I map it to a class (with a supertype MySupertype to differentiate from other Java classes)
members += f.toClass(f.fullyQualifiedName) [
superTypes += typeRef(MySupertype)
...
members += f.toConstructor [
for (p : f.params)
parameters += p.toParameter(p.name, p.parameterType)
body = f.block
]
...
]
What I need is to invoke this class as a function, e.g. using XFeatureCall. XFeatureCall::feature is a JvmIdentifiableElement and so is MyTypeDeclaration when mapped (in the compiler I will add a "new" prefix to call the class constructor). However, naturally, XFeatureClass does not include Java classes in its default scope.
So the question is, how to change this behavior? I need to include MyTypeDeclaration instances (or, more generally, Java classes with MySupertype as superclass) in XFeatureClass scope. I looked at the type computer, getLinkingCandidates and al but it looks too arcane for me.
I use version 2.15 as I need GWT...
Please help as I am really stuck at this point...
Thanks,
Martin

Jena Ontology API: Add property values for individual through Anonymous classes

For following model
i need to create individuals for class1 and set literal values for property4 and property5 for created individuals.
For this i am creating individual for Anonymous class2(in1) and setting property values for it. Then i create individual for Anonymous class1(in0) and use addproperty(property2,in1), again i create individual for class 1(in) and use addproperty(property1,in0).
String ns = "url.com";
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
OntClass class1 = model.createClass(ns+"class1");
OntClass Aclass1= model.createClass();
OntClass Aclass2= model.createClass();
OntProperty pro1 = model.createOntProperty(ns + "pro1");
OntProperty pro2 = model.createOntProperty(ns + "pro2");
OntProperty pro3 = model.createOntProperty(ns + "pro3");
DatatypeProperty pro4 = model.createDatatypeProperty(ns + "pro4");
DatatypeProperty pro5 = model.createDatatypeProperty(ns + "pro5");
Individual in1 = Aclass2.createIndividual(ns + "in1");
in1.addProperty( pro4, model.createTypedLiteral( 50 ) )
.addProperty( pro5, model.createTypedLiteral( 60) );
Individual in0=Aclass1.createIndividual(ns+"in2");
in0.addProperty(pro2,in1);
Individual in=class1.createIndividual(ns+"indi");
in.addProperty(pro1, in0);
this is giving following exception when run
Exception in thread "main" com.hp.hpl.jena.ontology.ProfileException: Attempted to use language construct DATATYPE_PROPERTY that is not supported in the current language profile: RDFS
at com.hp.hpl.jena.ontology.impl.OntModelImpl.checkProfileEntry(OntModelImpl.java:3058)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.createDatatypeProperty(OntModelImpl.java:1395)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.createDatatypeProperty(OntModelImpl.java:1375)
at test1.Hello.main(Hello.java:46)
What am i doing wrong and is there a better way for doing this?
The spec is wrong, it does not support owl:DatatypeProperty (and a lot of things from OntModel), but only RDFS vocabulary.
Try OntModelSpec.OWL_DL_MEM. It should eliminate exception.
But note: OntModelSpec#OWL_DL_MEM is about OWL1-DL, not OWL2DL. Jena does not support OWL2 at all.
If you want to use full OWL2DL specification with Jena, you can take a look on ONT-API, which is jena-based OWL-API.

How to access the methods for a higher rule?

During writing validation rules a came across the problem that I need some content from a rule in my grammar which is hierarchically higher than the one I pass to my validationMethod.
I know that I can refer to a "higher" rule with .eContainer but then I don't have a clue how to access the values I want to.
For example I have the following grammar snippet:
rule1:
name=ID content=rule2
;
rule2:
<<whatever content>>
;
If I have a normal validationMethod with the argument rule1 then I can access the name via .name but when I give rule2 as an argument and then referring to rule via .eConatiner the .name method does not exist.
Greetings Krzmbrzl
EObject is the root class of all AST node classes. It comes from the EMF Ecore framework which is used by Xtext to generate the AST implementation. Therefore, the EObject class contains a lot of the tree structure features, e.g., iterating through a tree. The EObject.eContainer() method returns an element of type EObject which actually is the super type of the type of the actual returned object. To get access to methods of the next higher element, you have to cast the eContainers methods result like this:
#Check
public void check(rule2 r2) {
EObject o = r2.eContainer();
rule1 r1 = (rule1) o;
String r1Name = r1.getName();
}
If the type of the parent object is ambigous, you should test whether the actual type is the expected with an instanceof expression:
#Check
public void check(rule2 r2) {
EObject o = r2.eContainer();
if (o instanceof rule1) {
rule1 r1 = (rule1) o;
String r1Name = r1.getName();
}
}
Xtend provide the same instanceof-expression like Java. But if the object to be checked definetly can have more then a few types, you can use Xtends really powerful switch expression. It supports so called type guards. You can switch over any object and instead of case value: guards simply write the a concrete type:
switch (anyAbstractTypeObject) {
ConcreteSubtypeA: {...}
ConcreteSubtypeB: {...}
}
This is an elegant shorthand if-instanceof-eleseif-... in Xtend.

Store data in Jena TDB and use reasoning

I have an OWL ontology file as RDF and want to store my data in a TDB and want to use reasoning. Actually this sounds simple so far :)
But here is the point where I'm confuesd:
I created a TDB an stored via SPARQL some statements. Then I tried to load the TDB via a model and OWL reasoner:
OntModelSpec ontModelSpec = OntModelSpec.OWL_MEM;
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
ontModelSpec.setReasoner(reasoner);
Model schemaModel = FileManager.get().loadModel("D:/Users/jim/Desktop/ontology/schema.rdf");
OntModel schema = ModelFactory.createOntologyModel( ontModelSpec, schemaModel);
Location location = new Location("D:/Users/jim/Desktop/jena-fuseki-0.2.5/DB");
Dataset dataset = TDBFactory.createDataset(location);
Model model = dataset.getDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(ontModelSpec, model);
When I now create new resources via API, they are not stored in the TDB. And I'm not able to see the Statments have added via SPARQL?!
The SPAQRL statement shows me only the entries I've added with SPARQL
QueryExecution qExec = QueryExecutionFactory.create(
StrUtils.strjoinNL("SELECT ?s ?p ?prop",
"WHERE {?s ?p ?prop}"),
dataset) ;
ResultSet rs = qExec.execSelect() ;
try {
ResultSetFormatter.out(rs) ;
} finally { qExec.close() ; System.out.println("closed connection");}
and this returns only the Resource added with the API
System.out.print("instance: " + ontModel.getResource(NS + "TestItem"));
And when I call this:
ExtendedIterator<Statement> iter = ontModel.listStatements();
I get the following exception:
org.openjena.atlas.lib.InternalErrorException: Invalid id node for subject (null node): ([0000000000000067], [0000000000000093], [00000000000000C8])
Is someone able to explain that behavior? Or could someone please give me a hint how to separate schema and date with TDB in right way with using the OntModel?
Partial answer:
org.openjena.atlas.lib.InternalErrorException: Invalid id node for subject (null node): ([0000000000000067], [0000000000000093], [00000000000000C8])
You are using TDB without transactions - try adding TDB.sync before exiting to flush changes to the disk.

Resources