Package org.ontoware.rdf2go.model

Examples of org.ontoware.rdf2go.model.Model


    QueryExecution qexec = QueryExecutionFactory.create(jenaQuery,
        this.dataset);

    if (jenaQuery.isDescribeType()) {
      com.hp.hpl.jena.rdf.model.Model m = qexec.execDescribe();
      Model resultModel = new ModelImplJena(null, m, Reasoning.none);
      resultModel.open();
      return resultModel;
    } else {
      throw new RuntimeException(
          "Cannot handle this type of query! Please use DESCRIBE.");
    }
View Full Code Here


public class TestSetup {
 
  @Test
  public void testSetup() {
    Model model = RDF2Go.getModelFactory().createModel();
    model.open();
    assertNotNull(model);
    assertTrue(model.isOpen());
    model.close();
  }
View Full Code Here

   * @throws ModelRuntimeException
   * @throws IOException
   */
  public static Model loadFoaf(ModelFactory factory) throws IOException,
      ModelRuntimeException {
    Model result = factory.createModel();
    result.open();
    InputStream in = getFoafAsStream();
    try {
      result.readFrom(in);
    } finally {
      in.close();
    }
    return result;
  }
View Full Code Here

   * @throws ModelRuntimeException
   * @throws IOException
   */
  public static Model loadICAL(ModelFactory factory) throws IOException,
      ModelRuntimeException {
    Model result = factory.createModel();
    result.open();
    InputStream in = getICALAsStream();
    try {
      result.readFrom(in);
    } finally {
      in.close();
    }
    return result;
  }
View Full Code Here

    public void applyRule(Model model, Map<String,URI> namespaceMap) {
    searchAndReplace(model, this.searchURIPrefix, this.replaceURIPrefix);
  }
 
  public static void searchAndReplace(Model model, String searchURIPrefix, String replaceURIPrefix) {
    Model add = RDF2Go.getModelFactory().createModel();
    add.open();
   
    Model remove = RDF2Go.getModelFactory().createModel();
    remove.open();
   
    ClosableIterator<Statement> it = model.iterator();
    while(it.hasNext()) {
      Statement stmt = it.next();
      Resource s = stmt.getSubject();
      URI p = stmt.getPredicate();
      Node o = stmt.getObject();
     
      boolean match = false;
      if(s instanceof URI && s.asURI().toString().startsWith(searchURIPrefix)) {
        match = true;
        String sURI = s.asURI().toString().replace(searchURIPrefix, replaceURIPrefix);
        s = new URIImpl(sURI);
      }
      if(p.toString().startsWith(searchURIPrefix)) {
        match = true;
        String pURI = p.toString().replace(searchURIPrefix, replaceURIPrefix);
        p = new URIImpl(pURI);
       
      }
      if(o instanceof URI && o.asURI().toString().startsWith(searchURIPrefix)) {
        match = true;
        String oURI = o.asURI().toString().replace(searchURIPrefix, replaceURIPrefix);
        o = new URIImpl(oURI);
      }
     
      if(match) {
        remove.addStatement(stmt);
        add.addStatement(s, p, o);
      }
    }
    it.close();
    ClosableIterator<Statement> addIt = add.iterator();
    ClosableIterator<Statement> removeIt = remove.iterator();
    model.update(new DiffImpl(addIt, removeIt));
    addIt.close();
    removeIt.close();
    add.close();
    remove.close();
  }
View Full Code Here

  @Override
  public void close() {
    if(this.isOpen()) {
      try {
        for(Iterator<RepositoryModel> i = this.openModels.keySet().iterator(); i.hasNext();) {
          Model m = i.next();
          if(m != null)
            m.close();
        }
        this.connection.close();
      } catch(RepositoryException e) {
        throw new ModelRuntimeException(e);
      } finally {
View Full Code Here

  /**
   * @param m the model to copy
   * @return a copy of the model in a memory model
   */
  public static Model copyModel(Model m) {
    Model res = RDF2Go.getModelFactory().createModel();
    res.open();
    res.addAll(m.iterator());
    return res;
  }
View Full Code Here

   * @param string the string with the serialized model
   * @param syntax the syntax to use
   * @return the model that was serialised.
   */
  public static Model stringToModel(String string, Syntax syntax) {
    Model m = RDF2Go.getModelFactory().createModel();
    m.open();
    StringReader s = new StringReader(string);
    try {
      m.readFrom(s, syntax);
      return m;
    } catch(Exception e) {
      throw new ModelRuntimeException(e);
    } finally {
      s.close();
View Full Code Here

   * @param model which should be stripped of unwanted languagetagged literals
   * @param language language which should be kept
   * @return a Model that contains only literals in the desired language
   */
  public static Model selectLanguage(Model model, String language) {
    Model result = RDF2Go.getModelFactory().createModel();
    result.open();
    ClosableIterator<Statement> it = model.iterator();
    while(it.hasNext()) {
      Statement s = it.next();
      if(s.getObject() instanceof LanguageTagLiteral) {
        LanguageTagLiteral lit = s.getObject().asLanguageTagLiteral();
        if(lit.getLanguageTag().startsWith(language)) {
          result.addStatement(s);
        }
        // else don't copy
      } else {
        result.addStatement(s);
      }
    }
    it.close();
    return result;
  }
View Full Code Here

        throw new IllegalStateException();
      }
     
      // create a temporary Model for the last URI and let it remove all
      // statements
      Model tmpModel = null;
     
      try {
        tmpModel = new RepositoryModel(this.lastURI, RepositoryModelSet.this.repository);
        tmpModel.removeAll();
      } finally {
        if(tmpModel != null) {
          tmpModel.close();
        }
        this.lastURI = null;
      }
    }
View Full Code Here

TOP

Related Classes of org.ontoware.rdf2go.model.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.