示例#1
0
  @Test
  public void testUpdate() throws Exception {
    Resource rhmRes = model.getResource(FakeRDFModel.rhm);
    Property name = model.getProperty(foaf + "name");

    Statement nameSt = rhmRes.listProperties(name).nextStatement();
    String originalName = nameSt.getLiteral().getString();

    // assume update is always first remove and then add
    model.remove(nameSt);
    model.add(rhmRes, name, "TESTNAME");

    assert changes.size() == 2;
    assert rhmRes.listProperties(name).toList().size() == 1;
    assert rhmRes.listProperties(name).nextStatement().getLiteral().getString().equals("TESTNAME");

    changes.undo();

    assert changes.size() == 2;
    assert rhmRes.listProperties(name).toList().size() == 1;
    assert rhmRes
        .listProperties(name)
        .nextStatement()
        .getLiteral()
        .getString()
        .equals(originalName);

    changes.redo();

    assert changes.size() == 2;
    assert rhmRes.listProperties(name).toList().size() == 1;
    assert rhmRes.listProperties(name).nextStatement().getLiteral().getString().equals("TESTNAME");
  }
 protected synchronized Map<Pattern, String> buildUrlPatternToURI() {
   OntModel displayModel = (OntModel) getServletContext().getAttribute("displayOntModel");
   Map<Pattern, String> map = new HashMap<Pattern, String>();
   StmtIterator stmts =
       displayModel.listStatements(null, DisplayVocabulary.URL_MAPPING, (Literal) null);
   while (stmts.hasNext()) {
     Statement stmt = stmts.nextStatement();
     if (stmt.getSubject().isURIResource() && stmt.getObject().isLiteral()) {
       Resource r = (Resource) stmt.getSubject().as(Resource.class);
       Pattern regex = Pattern.compile(stmt.getLiteral().getLexicalForm());
       map.put(regex, r.getURI());
     }
   }
   return map;
 }
  @Override
  public void indexStatement(Statement s) {
    if (!indexThisStatement(s)) return;

    try {
      Node subject = s.getSubject().asNode();

      if (!s.getObject().isLiteral() || !LARQ.isString(s.getLiteral())) return;

      Node object = s.getObject().asNode();

      // Note: if a subject occurs twice with an indexable string,
      // there will be two hits later.
      index.index(subject, object.getLiteralLexicalForm());
    } catch (Exception e) {
      throw new ARQLuceneException("indexStatement", e);
    }
  }