Skip to content

Commit

Permalink
Extended the OWL computer model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenR-York committed Jan 17, 2025
1 parent d6788c5 commit 5752046
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public Object getProperty(String property, IEolContext context) {
}
}

//return value.isEmpty() ? null : value; // Null returns cause issues with PropertyGetter which expects empty collections for no property matches
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
:alienBox51 a :GamingComputer .

:bigName42 a :Computer ;
:hasBundle :binNameSpecialBundle ;
:hasMotherBoard :bigNameSpecialMB,
:bundle :binNameSpecialBundle ;
:motherBoard :bigNameSpecialMB,
:nForce2 .

:whiteBoxZX a :Computer ;
:hasBundle :actionPack ;
:hasMotherBoard :nForce,
:bundle :actionPack ;
:motherBoard :nForce,
:unknownMB .

:actionPack a :GameBundle .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ eg:GamingComputer a owl:Class ;
owl:equivalentClass [ owl:intersectionOf ( [ a owl:Restriction ;
owl:hasValue eg:gamingGraphics ;
owl:onProperty eg:hasComponent ] [ a owl:Restriction ;
owl:onProperty eg:hasBundle ;
owl:onProperty eg:bundle ;
owl:someValuesFrom eg:GameBundle ] eg:Computer ) ] .

eg:budgetGraphics a eg:GraphicsCard .
Expand All @@ -28,18 +28,18 @@ eg:MotherBoard a owl:Class .

eg:gamingGraphics a eg:GraphicsCard .

eg:hasBundle a owl:ObjectProperty ;
eg:bundle a owl:ObjectProperty ;
rdfs:domain eg:Computer .

eg:hasMotherBoard a owl:ObjectProperty ;
eg:motherBoard a owl:ObjectProperty ;
rdfs:domain eg:Computer ;
rdfs:range eg:MotherBoard ;
rdfs:subPropertyOf eg:hasComponent .

eg:Computer a owl:Class ;
rdfs:subClassOf [ owl:intersectionOf ( [ a owl:Restriction ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ;
owl:onProperty eg:hasMotherBoard ] ) ] .
owl:onProperty eg:motherBoard ] ) ] .

eg:hasComponent a owl:ObjectProperty,
owl:TransitiveProperty .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Original example files from Jena's documentation.

Some changes have been made to these files in the RDFModel example.
Some changes have been made to these files.

hasMotherBoard is changed to motherBoard
hasBundle is changed to bundle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Collection;

import org.eclipse.epsilon.common.util.StringProperties;
Expand All @@ -25,12 +29,13 @@

public class RDFModelOWLReasonerTest {

private static final String OWL_DEMO_DATAMODEL = "resources/OWL/owlDemoData.rdf";
private static final String OWL_DEMO_SCHEMAMODEL = "resources/OWL/owlDemoSchema.rdf";
private static final String OWL_DEMO_DATAMODEL = "resources/OWL/owlDemoData.ttl";
private static final String OWL_DEMO_SCHEMAMODEL = "resources/OWL/owlDemoSchema.ttl";

private static final String LANGUAGE_PREFERENCE_EN_STRING = "en";
private static final String URI_BIGNAME42 = "urn:x-hp:eg/bigName42";

private static final String URI_ALIENBOX51 = "urn:x-hp:eg/alienBox51";

private RDFModel model;
private EolContext context;

Expand All @@ -48,17 +53,37 @@ public void loadModelDefaultDataSchemaLangPref() throws EolModelLoadingException
}

@Test
public void getMotherBoard() {
public void getMotherBoardTest() {
loadModelDefaults();
RDFResource element = model.getElementById(URI_BIGNAME42);
Object motherBoard = element.getProperty("eg:hasMotherBoard", context);
assertTrue("hasMotherBoard has max cardinality of 1 should only have that value returned ",
Object motherBoard = element.getProperty("eg:motherBoard", context);
assertTrue("motherBoard has max cardinality of 1 should only have that value returned ",
motherBoard instanceof RDFResource);
}

// TODO need a similar test to getMotherBoard but for the scenario where null should be returned (i.e. you have no motherboard)

// TODO need a test that would issue the warning
// TODO Review this test with Antonio.
// Proposed test: need a similar test to getMotherBoard but for the scenario where null should be returned (i.e. you have no motherboard)
// Getting an empty list back, because there is not motherboard there is also no max cardinality which could be evaluated to 1 and thus a single value or null.

@Test
public void getPropertyThatDoesNotExistAsNullTest() {
loadModelDefaults();
RDFResource element = model.getElementById(URI_ALIENBOX51);
Object motherBoard = element.getProperty("eg:motherBoard", context);
Collection<RDFResource> listMotherBoards = (Collection <RDFResource>) motherBoard;
//assertTrue("URI_ALIENBOX51 computer does not have motherBoard " + motherBoard, motherBoard == null);
assertTrue("URI_ALIENBOX51 computer does not have motherBoard ", listMotherBoards.size() == 0);
}

@Test
public void getMotherBoardTestIssuesWarning() throws IOException {
ByteArrayOutputStream errors = new ByteArrayOutputStream();
System.setErr(new PrintStream(errors));
loadModelDefaults();
RDFResource element = model.getElementById(URI_BIGNAME42);
Object motherBoard = element.getProperty("eg:motherBoard", context);
assertTrue("An error should be raised for max cardinality being raised ", errors.toString().contains("has a max cardinality 1, raw property values list contained"));
}

// Functions not tests

Expand Down

0 comments on commit 5752046

Please sign in to comment.