예제 #1
0
 protected void checkNumericContent(final Container cont2, final int num) {
   final NodeIterator nit = cont2.iterator();
   for (int i = 0; i < num; i += 1) {
     Assert.assertEquals(i, ((Literal) nit.nextNode()).getInt());
   }
   Assert.assertFalse(nit.hasNext());
 }
예제 #2
0
 protected void seeWhatsThere(final Container cont2, final boolean[] found) {
   final NodeIterator nit = cont2.iterator();
   while (nit.hasNext()) {
     final int v = ((Literal) nit.nextNode()).getInt();
     Assert.assertFalse(found[v]);
     found[v] = true;
   }
 }
예제 #3
0
 protected void retainOnlySpecified(final Container cont2, final int num, final boolean[] retain) {
   final NodeIterator nit = cont2.iterator();
   for (int i = 0; i < num; i++) {
     nit.nextNode();
     if (retain[i] == false) {
       nit.remove();
     }
   }
   Assert.assertFalse(nit.hasNext());
 }
예제 #4
0
 @Override
 public List<Node> getObjects(Node subject, Node predicate) {
   Model graph = null;
   GraphConnection graphConnection = null;
   try {
     graphConnection = openGraph();
     graph = graphConnection.getGraph();
     graph.enterCriticalSection(Lock.READ);
     SimpleSelector selector = getJenaSelector(graph, new StatementImpl(subject, predicate, null));
     NodeIterator it = graph.listObjectsOfProperty(selector.getSubject(), selector.getPredicate());
     List<Node> res = new ArrayList<Node>();
     while (it.hasNext()) {
       res.add(getNXRelationsNode(it.nextNode().asNode()));
     }
     return res;
   } finally {
     if (graph != null) {
       graph.leaveCriticalSection();
     }
     if (graphConnection != null) {
       graphConnection.close();
     }
   }
 }
예제 #5
0
  public void doctorModel(Model report, Model m, Model config) {
    this.input = m;
    this.repair = report;
    this.output = this.input;
    this.config = config;

    ResIterator it = repair.listSubjectsWithProperty(EYE.repairType, EYE.replaceNamespace);
    while (it.hasNext()) {
      /*
       * We are able to make one or more of the following assumptions;
       * (1)	o The Prefix is probably desired                                       \\
       * (3)	o The URI is likely misspelt                                          ===>  Work these with the precedence specified
       * (2)	o The URI is right, but the user mistakenly used a 'reserved' prefix   //
       */
      Resource curr = it.nextResource();
      String prefix =
          repair
              .listObjectsOfProperty(curr, EYE.onPrefix)
              .nextNode()
              .asNode()
              .getLiteralLexicalForm();
      String currUri = output.getNsPrefixURI(prefix);
      String configsUri = getConfigsUriFromPrefix(prefix);
      String configsPre = null;
      if (currUri != null) configsPre = getConfigsPrefixFromUri(currUri);
      if (configsUri != null) // Change the URI to a preferred one
      changeNsUri(currUri, configsUri);
      else if (configsPre != null) // Use that URI, but set the prefix according to config
      changeNsPrefix(prefix, configsPre);
      else // Use the 'expected' URI
      output.setNsPrefix(
            prefix,
            repair
                .listObjectsOfProperty(curr, EYE.expected)
                .nextNode()
                .asNode()
                .getLiteralLexicalForm());
    }

    it = repair.listSubjectsWithProperty(EYE.repairType, EYE.removeDuplicatePrefixes);
    while (it.hasNext()) {
      Resource curr = it.nextResource();
      NodeIterator it2 = repair.listObjectsOfProperty(curr, EYE.onPrefix);
      String uri =
          repair
              .listObjectsOfProperty(curr, EYE.multiplePrefixesForNamespace)
              .nextNode()
              .asNode()
              .getLiteralLexicalForm();
      if (it2.hasNext()) {
        boolean oneKept = false;
        while (it2.hasNext()) {
          RDFNode curra = it2.nextNode();
          if (m.getNsPrefixURI(curra.asNode().getLiteralLexicalForm()) != null)
            if (m.getNsPrefixURI(curra.asNode().getLiteralLexicalForm())
                .equals(uri)) // The prefix is still used in the model
            {
              if (oneKept) m.removeNsPrefix(curra.asNode().getLiteralLexicalForm());
              else oneKept = true;
            }
        }
      }
    }
  }