Skip to content

Commit d7e997a

Browse files
phillord-nclignazio1977
authored andcommitted
Fix Support anonymous individuals in SWRL rules #1164
1 parent b1768cd commit d7e997a

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

contract/src/test/java/org/semanticweb/owlapi/api/test/syntax/OWLXMLTestCase.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

66
import java.io.File;
7+
import java.util.*;
78

89
import org.junit.jupiter.api.Test;
910
import org.semanticweb.owlapi.api.test.baseclasses.TestBase;
@@ -12,7 +13,7 @@
1213
import org.semanticweb.owlapi.model.AxiomType;
1314
import org.semanticweb.owlapi.model.OWLAxiom;
1415
import org.semanticweb.owlapi.model.OWLObjectProperty;
15-
import org.semanticweb.owlapi.model.OWLOntology;
16+
import org.semanticweb.owlapi.model.*;
1617

1718
class OWLXMLTestCase extends TestBase {
1819

@@ -37,4 +38,28 @@ void shouldParseSWRLVariables() {
3738
assertTrue(out.contains("<Variable IRI=\"urn:swrl:var#x\"/>"), out);
3839
assertTrue(out.contains("<Variable IRI=\"urn:swrl:var#y\"/>"), out);
3940
}
41+
42+
@Test
43+
void shouldParseSwrlAnonIndividual() {
44+
OWLOntology o = loadFrom(new File(RESOURCES,
45+
"swrl_individual.owx"), new OWLXMLDocumentFormat(), m);
46+
Set<String> idsInRules = new HashSet<>();
47+
for (SWRLRule r : o.getAxioms(AxiomType.SWRL_RULE)) {
48+
Set<SWRLAtom> body = r.getBody();
49+
assertEquals(1, body.size());
50+
SWRLAtom element = body.iterator().next();
51+
assertTrue(element instanceof SWRLClassAtom);
52+
Set<OWLAnonymousIndividual> anonymousIndividuals = ((SWRLClassAtom) element)
53+
.getAnonymousIndividuals();
54+
assertEquals(1, anonymousIndividuals.size());
55+
String id = anonymousIndividuals.iterator().next().getID().getID();
56+
assertTrue(id.matches("_:genid\\d+"));
57+
idsInRules.add(id);
58+
}
59+
String out = saveOntology(o, new OWLXMLDocumentFormat()).toString();
60+
for (String id : idsInRules) {
61+
assertTrue(out.contains("<AnonymousIndividual nodeID=\"" + id
62+
+ "\"/>"));
63+
}
64+
}
4065
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
3+
xml:base="http://www.example.com/iri"
4+
xmlns:o="http://www.example.com/iri#"
5+
xmlns:owl="http://www.w3.org/2002/07/owl#"
6+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
7+
xmlns:xml="http://www.w3.org/XML/1998/namespace"
8+
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
9+
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
10+
ontologyIRI="http://www.example.com/iri"
11+
versionIRI="http://www.example.com/viri">
12+
<Prefix name="o" IRI="http://www.example.com/iri#"/>
13+
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
14+
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
15+
<Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
16+
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
17+
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
18+
<Declaration>
19+
<Class IRI="#A"/>
20+
</Declaration>
21+
<Declaration>
22+
<Class IRI="#B"/>
23+
</Declaration>
24+
<Declaration>
25+
<NamedIndividual IRI="#I"/>
26+
</Declaration>
27+
<DLSafeRule>
28+
<Body>
29+
<ClassAtom>
30+
<Class IRI="#A"/>
31+
<AnonymousIndividual nodeID="_:genid2147483648"/>
32+
</ClassAtom>
33+
</Body>
34+
<Head>
35+
<ClassAtom>
36+
<Class IRI="#B"/>
37+
<NamedIndividual IRI="#I"/>
38+
</ClassAtom>
39+
</Head>
40+
</DLSafeRule>
41+
</Ontology>

parsers/src/main/java/org/semanticweb/owlapi/owlxml/parser/PARSER_OWLXMLVocabulary.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,11 @@ void handleChild(ClassEH<? extends OWLClassExpression, ?> h) {
19201920
void handleChild(IndividualEH h) {
19211921
builder.with(swrlInd(h.getOWLObject()));
19221922
}
1923+
1924+
@Override
1925+
void handleChild(AnonEH h) {
1926+
builder.with(swrlInd(h.getOWLObject()));
1927+
}
19231928
}
19241929

19251930

0 commit comments

Comments
 (0)