Get InverseObjectProperty with a reasoner - owl

How can I query an inverse of an object property using a reasoner?
For example, a Person can have a Gun and vice versa:
<Declaration>
<ObjectProperty IRI="#hasOwner"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasGun"/>
</Declaration>
<InverseObjectProperties>
<ObjectProperty IRI="#hasOwner"/>
<ObjectProperty IRI="#hasGun"/>
</InverseObjectProperties>
Because there are simple axioms, I tried to come up with an uncomplicatedstar function to handle this:
OWLObjectProperty getOWLInverseRelation(OWLReasoner reasoner, OWLObjectProperty relation) {
Set<OWLObjectPropertyExpression> inverseRelationExprs = reasoner.getInverseObjectProperties(relation).getEntities();
if (inverseRelationExprs.size() != 2) return null;
Iterator<OWLObjectPropertyExpression> inverseRelationExprIter = inverseRelationExprs.iterator();
OWLObjectPropertyExpression inverseRelationExpr = inverseRelationExprIter.next();
if (inverseRelationExpr.getNamedProperty().getIRI().getShortForm().equals(relation.getIRI().getShortForm()))
inverseRelationExpr = inverseRelationExprIter.next();
return inverseRelationExpr.asOWLObjectProperty();
}
Is this function a straightforward and simple way to get an inverse object property?

The OWLObjectPropertyExpression instances returned by reasoner.getInverseObjectProperties(relation).getEntities() are already the inverses of relation. Each one of them is inferred to be an inverse of your input - they can be equivalent to each other.

Related

AttributeError: 'Group' object has no attribute 'dtype'

I want to combine the datasets within a single hdf5 file to form one dataset in a seperate file, but am struggling to set the dtype of the new dataset. I am getting the error AttributeError: 'Group' object has no attribute 'dtype' on the line with ds_0_dtype = h5f1[ds].dtype. the code below (based on some example code posted on stackoverflow)
with
h5py.File('xxx_xxx_signals.hdf5','r') as h5f1 , \
h5py.File('file2.h5','w') as h5f2 :
for i, ds in enumerate(h5f1.keys()) :
if i == 0:
ds_0 = ds
ds_0_dtype = h5f1[ds].dtype
n_rows = h5f1[ds].shape[0]
n_cols = h5f1[ds].shape[1]
else:
if h5f1[ds].dtype != ds_0_dtype :
print(f'Dset 0:{ds_0}: dtype:{ds_0_dtype}')
print(f'Dset {i}:{ds}: dtype:{h5f1[ds].dtype}')
sys.exit('Error: incompatible dataset dtypes')
if h5f1[ds].shape[0] != n_rows :
print(f'Dset 0:{ds_0}: shape[0]:{n_rows}')
print(f'Dset {i}:{ds}: shape[0]:{h5f1[ds].shape[0]}')
sys.exit('Error: incompatible dataset shape')
n_cols += h5f1[ds].shape[1]
prev_ds = ds
h5f2.create_dataset('ds_xxxx', dtype=ds_0_dtype, shape=(n_rows,n_cols), maxshape=(n_rows,None))
first = 0
for ds in h5f1.keys() :
xfer_arr = h5f1[ds][:]
last = first + xfer_arr.shape[1]
h5f2['ds_xxxx'][:, first:last] = xfer_arr[:]
first = last
Likely you have 1 or more Groups in addition to Datasets at the Root level. h5f1.keys() accesses all Nodes -- which can be Datasets or Groups. You need to add a test to skip over Groups. You do this with an isinstance() logic test. Something like this:
else:
if not isinstance(h5f1[ds], h5py.Dataset) :
print(f'Node 0:{ds_0}: is not a dataset')
sys.exit('Error: unexpected Group; only Datasets expected')
if h5f1[ds].dtype != ds_0_dtype :
Once you know how to identify groups, you can also modify code to avoid copying them to the second file. However, that may not be your desired result. I have an extended SO post on using isinstance(). See this link:
Is there a way to get datasets in all groups at once in h5py?

min cardinality not working as expected in Protege

I'm a beginner in Protege / OWL and I'm having trouble understanding why max cardinality is working and min cardinality is not.
I tried Hermit Pellet and Fact as reasoners. I know about the Open World Assumtion, but this seems not logical to me.
I want to express that there must be at least 2 Persons in a Marriage event.
Class: MarriageEvent
EquivalentTo:
This works:
MarriageEvent and is_event_of max 2 Person
And this not:
MarriageEvent and is_event_of min 2 Person
All individuals are declared as different individuals.
My ontology:
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.semanticweb.org/anato/ontologies/2017/7/untitled-ontology-184"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="http://www.semanticweb.org/anato/ontologies/2017/7/untitled-ontology-184">
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<NamedIndividual IRI="#Peter"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Julia"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#is_event_of"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Max"/>
</Declaration>
<Declaration>
<Class IRI="#Person"/>
</Declaration>
<Declaration>
<NamedIndividual IRI="#Event_Marriage"/>
</Declaration>
<Declaration>
<Class IRI="#MarriageEvent"/>
</Declaration>
<EquivalentClasses>
<Class IRI="#MarriageEvent"/>
<ObjectIntersectionOf>
<Class IRI="#MarriageEvent"/>
<ObjectMinCardinality cardinality="2">
<ObjectProperty IRI="#is_event_of"/>
<Class IRI="#Person"/>
</ObjectMinCardinality>
</ObjectIntersectionOf>
</EquivalentClasses>
<EquivalentClasses>
<Class IRI="#MarriageEvent"/>
<ObjectIntersectionOf>
<Class IRI="#MarriageEvent"/>
<ObjectMaxCardinality cardinality="2">
<ObjectProperty IRI="#is_event_of"/>
<Class IRI="#Person"/>
</ObjectMaxCardinality>
</ObjectIntersectionOf>
</EquivalentClasses>
<DisjointClasses>
<Class IRI="#MarriageEvent"/>
<Class IRI="#Person"/>
</DisjointClasses>
<ClassAssertion>
<Class IRI="#MarriageEvent"/>
<NamedIndividual IRI="#Event_Marriage"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Person"/>
<NamedIndividual IRI="#Julia"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Person"/>
<NamedIndividual IRI="#Max"/>
</ClassAssertion>
<ClassAssertion>
<Class IRI="#Person"/>
<NamedIndividual IRI="#Peter"/>
</ClassAssertion>
<DifferentIndividuals>
<NamedIndividual IRI="#Event_Marriage"/>
<NamedIndividual IRI="#Julia"/>
<NamedIndividual IRI="#Max"/>
<NamedIndividual IRI="#Peter"/>
</DifferentIndividuals>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#is_event_of"/>
<NamedIndividual IRI="#Event_Marriage"/>
<NamedIndividual IRI="#Julia"/>
</ObjectPropertyAssertion>
<ObjectPropertyAssertion>
<ObjectProperty IRI="#is_event_of"/>
<NamedIndividual IRI="#Event_Marriage"/>
<NamedIndividual IRI="#Peter"/>
</ObjectPropertyAssertion>
<SubObjectPropertyOf>
<ObjectProperty IRI="#is_event_of"/>
<ObjectProperty abbreviatedIRI="owl:topObjectProperty"/>
</SubObjectPropertyOf>
<IrreflexiveObjectProperty>
<ObjectProperty IRI="#is_event_of"/>
</IrreflexiveObjectProperty>
<ObjectPropertyDomain>
<ObjectProperty IRI="#is_event_of"/>
<Class IRI="#MarriageEvent"/>
</ObjectPropertyDomain>
<ObjectPropertyRange>
<ObjectProperty IRI="#is_event_of"/>
<Class IRI="#Person"/>
</ObjectPropertyRange>
</Ontology>
<!-- Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi -->
min 2 Person will not complain about marriages where only one person is known because of the Open World Assumption. Just because the second party to the wedding is not known, does not mean that it's not there.
Semantic Web languages such as OWL make the open-world assumption. The
absence of a particular statement within the web means, in principle,
that the statement has not been made explicitly yet, irrespective of
whether it would be true or not, and irrespective of whether we
believe that it would be true or not. In essence, from the absence of
a statement alone, a deductive reasoner cannot (and must not) infer
that the statement is false.
https://en.wikipedia.org/wiki/Open-world_assumption
The absence of a statement about the presence of a 2nd individual does not imply there is not a 2nd individual.

ATU Reports throws NullPointerException

I am trying to use ATU Reports for my project. The suite has around 25 #Test methods. After the completion of execution, a null pointer exception is got.
Exception in thread "main" java.lang.IllegalStateException:
java.lang.NullPointe rException
at atu.testng.reports.listeners.ATUReportsListener.onFinish(Unknown Sour
ce)
at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:204)
at org.testng.SuiteRunner.run(SuiteRunner.java:264)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.TestNG.privateMain(TestNG.java:1355)
at org.testng.TestNG.main(TestNG.java:1324) Caused by: java.lang.NullPointerException
at atu.testng.reports.writers.CurrentRunPageWriter.getTestCaseHTMLPath(U
nknown Source)
at atu.testng.reports.writers.CurrentRunPageWriter.writeFailedData(Unkno
wn Source)
at atu.testng.reports.writers.CurrentRunPageWriter.content(Unknown Sourc
e)
at atu.testng.reports.listeners.ATUReportsListener.generateCurrentRunPag
e(Unknown Source)
... 10 more
Another observation is that the ATU report is generated successfully when the #Test methods is around 5. Could it be that a particular #Test method is causing this NullPointerException?
testng.xml file is as below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name="A1" />
<include name="A2" />
<include name="B1" />
</run>
</groups>
<classes>
<class name="com.test.testcases.Class1"/>
<class name="com.test.testcases.Class2"/>
<class name="com.test.testcases.Class3"/>
</classes>
</test> <!-- Test -->
<listeners>
<listener class-name="atu.testng.reports.listeners.ATUReportsListener"></listener>
<listener class-name="atu.testng.reports.listeners.ConfigurationListener"></listener>
<listener class-name="atu.testng.reports.listeners.MethodListener"></listener>
</listeners>
</suite> <!-- Suite -->
Something is null in this code (decompiled from ATU 5.1.1):
public void onFinish(ISuite paramISuite)
{
try
{
this.iSuite = paramISuite;
String str1 = SettingsFile.get("passedList") + this.passedTests.size() + ';';
String str2 = SettingsFile.get("failedList") + this.failedTests.size() + ';';
String str3 = SettingsFile.get("skippedList") + this.skippedTests.size() + ';';
SettingsFile.set("passedList", str1);
SettingsFile.set("failedList", str2);
SettingsFile.set("skippedList", str3);
HTMLDesignFilesJSWriter.lineChartJS(str1, str2, str3, this.runCount);
HTMLDesignFilesJSWriter.barChartJS(str1, str2, str3, this.runCount);
HTMLDesignFilesJSWriter.pieChartJS(this.passedTests.size(), this.failedTests.size(), this.skippedTests.size(), this.runCount);
generateIndexPage();
paramISuite.setAttribute("endExecution", Long.valueOf(System.currentTimeMillis()));
long l = ((Long)paramISuite.getAttribute("startExecution")).longValue();
generateConsolidatedPage();
generateCurrentRunPage(l, System.currentTimeMillis());
startReportingForPassed(this.passedTests);
startReportingForFailed(this.failedTests);
startReportingForSkipped(this.skippedTests);
if (Directory.generateExcelReports) {
ExcelReports.generateExcelReport(Directory.RUNDir + Directory.SEP + "(" + Directory.REPORTSDIRName + ") " + Directory.RUNName + this.runCount + ".xlsx", this.passedTests, this.failedTests, this.skippedTests);
}
if (Directory.generateConfigReports) {
ConfigurationListener.startConfigurationMethodsReporting(this.runCount);
}
if (Directory.recordSuiteExecution) {
try
{
this.recorder.stop();
}
catch (Throwable localThrowable) {}
}
}
catch (Exception localException)
{
throw new IllegalStateException(localException);
}
}
I suspect the issue comes from long l = ((Long)paramISuite.getAttribute("startExecution")).longValue(); because TestNG has some issues with listeners.
What you should do is installing a java decompiler in your IDE (for example http://jd.benow.ca/). Then, in debug mode, you'll be able to find where exactly is the issue.
You should try the latest TestNG version (6.9.12) too which is supposed to fix the previous listener issues.
While debugging manually and running the classes individually I found out that one of the class was throwing a nullpointer exception as there was a mismatch in the number of parameters passed.

OWL: how to limit the range of a value

For example, I need to describe a dog between age 1 and 4. How do I restrict the value range of a property? There are minCardinality and maxCardinality for number of property. But not suitable for my example.
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
As an concrete example, how to translate above xsd to owl?
You can define a qualified cardinality restriction directly as a local class restriction. For example, to define that an amoeba has an age range of 1 to 4, use the following:
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://example.org/things#age"/>
<owl:maxQualifiedCardinality rdf:datatype="xs:nonNegativeInteger">4</owl:maxQualifiedCardinality>
<owl:onDataRange rdf:resource="http://example.org/things#Amoeba"/>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://example.org/things#age"/>
<owl:minQualifiedCardinality rdf:datatype="xs:nonNegativeInteger">1</owl:minQualifiedCardinality>
<owl:onDataRange rdf:resource="http://example.org/things#Amoeba"/>
</owl:Restriction>
</rdfs:subClassOf>
That's a bit difficult to read. The equivalent Turtle serialization is considerably easier to read and manage (note the direct representation of triples. JSON-LD is another readily consumable text serialization for RDF):
rdfs:subClassOf [
rdf:type owl:Restriction ;
owl:maxQualifiedCardinality "4"^^xs:nonNegativeInteger ;
owl:onDataRange ex:Amoeba ;
owl:onProperty ex:age ;
] ;
rdfs:subClassOf [
rdf:type owl:Restriction ;
owl:minQualifiedCardinality "1"^^xs:nonNegativeInteger ;
owl:onDataRange ex:Amoeba ;
owl:onProperty ex:age ;
] ;

Delete XML nodes in SQL server based on conditions

I have xml that looks like
<MeasureSet>
<MeasureSetType val_type="name">Variant</MeasureSetType>
<Measure>
<MeasureType val_type="name">single nucleotide variant</MeasureType>
<AttributeSet>
<MeasureAttributeType val_type="name">HGVS</MeasureAttributeType>
<Attribute>NM_000054.4:c.838dupT</Attribute>
</AttributeSet>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed">10820168</ID>
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed" />
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed">9773787</ID>
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed">18726898</ID>
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed" />
</Citation>
</Measure>
</MeasureSet>
I want to delete the Citation element nodes that have Citation/ID/#Source = "PubMed" and Citation/ID is empty
This deletes only the ID element, but the correct ones
SET #myBlob.modify('delete //Citation/ID[#Source = ''PubMed''
and string-length(string(number(.))) = 0]')
and this deletes all Citation elements
SET #myBlob.modify('delete //Citation[ID/#Source = ''PubMed''
and string-length(string(number(.))) = 0]')
Seems there should be an easy solution I'm not hitting on. Any suggestions? Thanks
Your second one is checking the length of the wrong element - it's looking at (.), which is here the Citation element (because it's in a predicate on the Citation element). Use instead
SET #myBlob.modify('
delete //Citation[ID/#Source = ''PubMed''
and string-length(string(number(ID[1]))) = 0]')
where I have changed . to ID[1]. The [1] is needed because "'number()' requires a singleton (or empty sequence)".

Resources