private static void extractList(List<String> output, Resource head) {
    if (head.hasProperty(RDF.first))
      output.add(head.getProperty(RDF.first).getObject().asLiteral().getString());

    if (head.hasProperty(RDF.rest))
      extractList(output, head.getProperty(RDF.rest).getObject().asResource());
  }
Esempio n. 2
0
    @Override
    protected Serializable processMethod() throws AsyncException {
      StmtIterator mappings =
          m.listStatements(
              getHandler("mappings"), null, LocationMappingVocab.mapping, (RDFNode) null);

      for (; mappings.hasNext(); ) {
        Statement s = mappings.nextStatement();
        Resource mapping = s.getResource();

        if (mapping.hasProperty(getHandler(""), LocationMappingVocab.name)) {
          try {
            String name =
                mapping
                    .getRequiredProperty(getHandler("name"), LocationMappingVocab.name)
                    .getString();
            String altName =
                mapping
                    .getRequiredProperty(getHandler("altName"), LocationMappingVocab.altName)
                    .getString();
            addAltEntry(name, altName);
            log.log(Level.ALL, "Mapping: " + name + " => " + altName);
            //		                    log.debug("Mapping: "+name+" => "+altName) ;
          } catch (JenaException ex) {
            log.log(Level.ALL, "Error processing name mapping: " + ex.getMessage());
            //		                    log.warn("Error processing name mapping: "+ex.getMessage()) ;
            return null;
          }
        }

        if (mapping.hasProperty(getHandler(""), LocationMappingVocab.prefix)) {
          try {
            String prefix =
                mapping
                    .getRequiredProperty(getHandler("prefix"), LocationMappingVocab.prefix)
                    .getString();
            String altPrefix =
                mapping
                    .getRequiredProperty(getHandler("altPrefix"), LocationMappingVocab.altPrefix)
                    .getString();
            addAltPrefix(prefix, altPrefix);
            log.log(Level.ALL, "Prefix mapping: " + prefix + " => " + altPrefix);
            //		                    log.debug("Prefix mapping: "+prefix+" => "+altPrefix) ;
          } catch (JenaException ex) {
            log.log(Level.ALL, "Error processing prefix mapping: " + ex.getMessage());
            //		                    log.warn("Error processing prefix mapping: "+ex.getMessage()) ;
            return null;
          }
        }
      }

      return null;
    }
Esempio n. 3
0
 /** Run a single test of any sort, return true if the test succeeds. */
 public boolean doRunTest(Resource test) throws IOException {
   if (test.hasProperty(RDF.type, OWLTest.PositiveEntailmentTest)
       || test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)
       || test.hasProperty(RDF.type, OWLTest.OWLforOWLTest)
       || test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest)
       || test.hasProperty(RDF.type, OWLTest.TrueTest)) {
     // Entailment tests
     boolean processImports = test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest);
     Model premises = getDoc(test, RDFTest.premiseDocument, processImports);
     Model conclusions = getDoc(test, RDFTest.conclusionDocument);
     comprehensionAxioms(premises, conclusions);
     long t1 = System.currentTimeMillis();
     InfGraph graph = reasoner.bind(premises.getGraph());
     if (printProfile) {
       ((FBRuleInfGraph) graph).resetLPProfile(true);
     }
     Model result = ModelFactory.createModelForGraph(graph);
     boolean correct = WGReasonerTester.testConclusions(conclusions.getGraph(), result.getGraph());
     long t2 = System.currentTimeMillis();
     lastTestDuration = t2 - t1;
     if (printProfile) {
       ((FBRuleInfGraph) graph).printLPProfile();
     }
     if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)) {
       correct = !correct;
     }
     return correct;
   } else if (test.hasProperty(RDF.type, OWLTest.InconsistencyTest)) {
     //            System.out.println("Starting: " + test);
     Model input = getDoc(test, RDFTest.inputDocument);
     long t1 = System.currentTimeMillis();
     InfGraph graph = reasoner.bind(input.getGraph());
     boolean correct = !graph.validate().isValid();
     long t2 = System.currentTimeMillis();
     lastTestDuration = t2 - t1;
     return correct;
   } else if (test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
     // Not used normally becase we are not complete enough to prove consistency
     //            System.out.println("Starting: " + test);
     Model input = getDoc(test, RDFTest.inputDocument);
     long t1 = System.currentTimeMillis();
     InfGraph graph = reasoner.bind(input.getGraph());
     boolean correct = graph.validate().isValid();
     long t2 = System.currentTimeMillis();
     lastTestDuration = t2 - t1;
     return correct;
   } else {
     for (StmtIterator i = test.listProperties(RDF.type); i.hasNext(); ) {
       System.out.println("Test type = " + i.nextStatement().getObject());
     }
     throw new ReasonerException("Unknown test type");
   }
 }
Esempio n. 4
0
 @Test
 public void testPresentTotalCount() throws URISyntaxException {
   Integer totalResults = new Integer(17);
   Resource thisMetaPage = createMetadata(true, totalResults);
   Literal tr = thisMetaPage.getModel().createTypedLiteral(totalResults);
   assertTrue(thisMetaPage.hasProperty(OpenSearch.totalResults, tr));
 }
Esempio n. 5
0
 /** Run a single test of any sort, performing any appropriate logging and error reporting. */
 public void runTest(Resource test) {
   System.out.println("Running " + test);
   boolean success = false;
   boolean fail = false;
   try {
     success = doRunTest(test);
   } catch (Exception e) {
     fail = true;
     System.out.print("\nException: " + e);
     e.printStackTrace();
   }
   testCount++;
   if (success) {
     System.out.print((testCount % 40 == 0) ? ".\n" : ".");
     System.out.flush();
     passCount++;
   } else {
     System.out.println("\nFAIL: " + test);
   }
   Resource resultType = null;
   if (fail) {
     resultType = OWLResults.FailingRun;
   } else {
     if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)
         || test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
       resultType = success ? OWLResults.PassingRun : OWLResults.FailingRun;
     } else {
       resultType = success ? OWLResults.PassingRun : OWLResults.IncompleteRun;
     }
   }
   // log to the rdf result format
   Resource result =
       testResults
           .createResource()
           .addProperty(RDF.type, OWLResults.TestRun)
           .addProperty(RDF.type, resultType)
           .addProperty(OWLResults.test, test)
           .addProperty(OWLResults.system, jena2);
 }
Esempio n. 6
0
 @Test
 public void testAbsentTotalCount() throws URISyntaxException {
   Integer totalResults = null;
   Resource thisMetaPage = createMetadata(true, totalResults);
   assertFalse(thisMetaPage.hasProperty(OpenSearch.totalResults));
 }
Esempio n. 7
0
 @Test
 public void testItemEndpointHasCorrectType() throws URISyntaxException {
   Integer totalResults = null;
   Resource thisMetaPage = createMetadata(false, totalResults);
   assertTrue(thisMetaPage.hasProperty(RDF.type, API.ItemEndpoint));
 }
 private static void removeElementsWithoutType(Set<Resource> candidates, Resource type) {
   for (Iterator<Resource> it = candidates.iterator(); it.hasNext(); ) {
     Resource candidate = it.next();
     if (!candidate.hasProperty(RDF.type, type)) it.remove();
   }
 }
Esempio n. 9
0
 protected void checkType(Resource root, Resource type) {
   if (!root.hasProperty(RDF.type, type))
     throw new CannotConstructException(this.getClass(), root, type);
 }