From 6a559a415b3bdb3048021839e5bcf5bbf5aa4bbd Mon Sep 17 00:00:00 2001 From: RncLsn Date: Fri, 29 May 2015 11:37:19 +0100 Subject: Anonymous ontology id. --- src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | 12 ++++++++---- test/resources/LightTests.xml | 4 ++-- test/uk/ac/ox/cs/pagoda/query/CheckAnswers.java | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java index d961223..b92bceb 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java +++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java @@ -18,10 +18,13 @@ import uk.ac.ox.cs.pagoda.util.Utility; import java.io.*; import java.nio.file.Paths; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class RLPlusOntology implements KnowledgeBase { private static final String DEFAULT_ONTOLOGY_FILE_EXTENSION = "owl"; + private static final Pattern ONTOLOGY_ID_REGEX = Pattern.compile("ontologyid\\((?[a-z0-9\\-]+)\\)"); OWLOntologyManager manager; OWLDataFactory factory; String ontologyIRI; @@ -61,9 +64,10 @@ public class RLPlusOntology implements KnowledgeBase { try { IRI ontologyIri; if(ontology.isAnonymous()) { - String anonymousOntologySuffix = Long.toString(System.currentTimeMillis()); - ontologyIri = IRI.create("http://www.example.org/", "anonymous-ontology-" - + anonymousOntologySuffix + "." + DEFAULT_ONTOLOGY_FILE_EXTENSION); + Matcher matcher = ONTOLOGY_ID_REGEX.matcher(ontology.getOntologyID().toString().toLowerCase()); + if(!matcher.matches()) throw new Error("Anonymous ontology without internal id"); + ontologyIri = + IRI.create("http://www.example.org/", matcher.group("id") + "." + DEFAULT_ONTOLOGY_FILE_EXTENSION); } else ontologyIri = inputOntology.getOntologyID().getOntologyIRI(); @@ -79,7 +83,7 @@ public class RLPlusOntology implements KnowledgeBase { IRI rlOntologyIRI = IRI.create(ontologyIriPrefix, originalFileName + "-RL." + originalExtension); outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), originalFileName + "-RL." + originalExtension).toString(); - IRI rlDocumentIRI = IRI.create(outputPath); + IRI rlDocumentIRI = IRI.create("file://" + outputPath); outputOntology = manager.createOntology(rlOntologyIRI); manager.setOntologyDocumentIRI(outputOntology, rlDocumentIRI); diff --git a/test/resources/LightTests.xml b/test/resources/LightTests.xml index bd0ea93..a30c436 100644 --- a/test/resources/LightTests.xml +++ b/test/resources/LightTests.xml @@ -11,8 +11,8 @@ - - + + \ No newline at end of file diff --git a/test/uk/ac/ox/cs/pagoda/query/CheckAnswers.java b/test/uk/ac/ox/cs/pagoda/query/CheckAnswers.java index f16d657..97e3a57 100644 --- a/test/uk/ac/ox/cs/pagoda/query/CheckAnswers.java +++ b/test/uk/ac/ox/cs/pagoda/query/CheckAnswers.java @@ -31,7 +31,6 @@ public class CheckAnswers { Set givenAnswersRecords = gson.fromJson(givenReader, cqType); for(QueryRecord computedAnswersRecord : computedAnswersRecords) { - if(computedAnswersRecord.queryID == 8) continue; // DEBUG Set givenAnswers = null; for(QueryRecord givenAnswersRecord : givenAnswersRecords) { if(givenAnswersRecord.queryID == computedAnswersRecord.queryID) { @@ -44,7 +43,7 @@ public class CheckAnswers { Set computedAnswers = computedAnswersRecord.soundAnswerTuples; Assert.assertEquals(computedAnswers.size(), givenAnswers.size(), - "Different number sound answers for query " + computedAnswersRecord.queryID + "!" + "Different number of sound answers for query " + computedAnswersRecord.queryID + "!" + "Expected " + givenAnswers.size() + ", got " + computedAnswers.size()); Assert.assertEquals(computedAnswers, givenAnswers, "Different sound answers for query " + computedAnswersRecord.queryID + "!"); -- cgit v1.2.3