44import static org .junit .jupiter .api .Assertions .assertTrue ;
55
66import java .io .File ;
7+ import java .util .*;
78
89import org .junit .jupiter .api .Test ;
910import org .semanticweb .owlapi .api .test .baseclasses .TestBase ;
1213import org .semanticweb .owlapi .model .AxiomType ;
1314import org .semanticweb .owlapi .model .OWLAxiom ;
1415import org .semanticweb .owlapi .model .OWLObjectProperty ;
15- import org .semanticweb .owlapi .model .OWLOntology ;
16+ import org .semanticweb .owlapi .model .* ;
1617
1718class 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}
0 commit comments