Package org.ontoware.rdf2go.model

Examples of org.ontoware.rdf2go.model.Model


  }
 
  public static Model loadFromClassPathResource( String resourceName ) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream in = cl.getResourceAsStream(resourceName);
    Model model = RDF2Go.getModelFactory().createModel();
    model.open();
    try {
      model.readFrom(in);
    } catch (ModelRuntimeException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
View Full Code Here


   *            location of the schema file. can end be in N3 (*.n3) or
   *            N-TRIPLE (*.nt) notation
   * @return a Jena Model
   */
  public static Model read(String filename) {
    Model m = RDF2Go.getModelFactory().createModel();
    m.open();

    FileInputStream fis;
    File f = new File(filename);
    try {
      fis = new FileInputStream(f);

      Syntax syntax = Syntax.forFileName(filename);
   
      try {
        m.readFrom(fis, syntax);
      } catch (ModelRuntimeException e) {
        throw new RuntimeException(e);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
View Full Code Here

     * first of all we have to instantiate a RDF2GO model with an underlying
     * framework here we choose Jena
     */

    // no inferencing
    Model model = new ModelImplJena26(Reasoning.none);
    // alternatives
    // new ModelImplYars();
    // new ModelImplNG4J();
   
    /*
     * before we can do anything useful, we have to define the uris we want
     * to use
     */
    // use the uris defined by foaf
    URI foafName = model.createURI("http://xmlns.com/foaf/0.1/name");
    URI foafPerson = model.createURI("http://xmlns.com/foaf/0.1/Person");
    URI foafTitle = model.createURI("http://xmlns.com/foaf/0.1/title");
    URI foafKnows = model.createURI("http://xmlns.com/foaf/0.1/knows");
    URI foafHomepage = model.createURI("http://xmlns.com/foaf/0.1/homepage");
    // use a blank node for the person
    BlankNode werner = model.createBlankNode();
   
    /*
     * now we can add statements to the model (for easier reading we
     * replaced the blank nodes cryptical letters with a human readable
     * version - you will see something different when exectuing this
     * example
     */
    // _:blankNodeWerner
    // <http://xmlns.com/foaf/0.1/homepage>
    // <http://www.blue-agents.com> .
    model.addStatement(werner, foafHomepage, model.createURI("http://www.blue-agents.com"));
    // _:blankNodeWerner
    // <http://xmlns.com/foaf/0.1/title>
    // "Mr" .
    model.addStatement(werner, foafTitle, "Mr");
    // _:blankNodeWerner
    // <http://xmlns.com/foaf/0.1/name>
    // "Werner Thiemann" .
    model.addStatement(werner, foafName, "Werner Thiemann");
   
    // _:blankNodeWerner
    // <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
    // <http://xmlns.com/foaf/0.1/Person> .
    model.addStatement(werner, RDF.type, foafPerson);
   
    BlankNode max = model.createBlankNode();
    // _:blankNodeMax
    // <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
    // <http://xmlns.com/foaf/0.1/Person> .
    model.addStatement(max, RDF.type, foafPerson);
    // _:blankNodeMax
    // <http://xmlns.com/foaf/0.1/name>
    // "Max Voelkel" .
    model.addStatement(max, foafName, "Max V�lkel");
    // _:blankNodeMax
    // <http://www.w3.org/2000/01/rdf-schema#seeAlso>
    // <http://www.aifb.uni-karlsruhe.de/WBS/mvo/foaf.rdf.xml> .
    model.addStatement(max, RDFS.seeAlso, model.createURI("http://www.xam.de/foaf.rdf.xml"));
   
    // link via foaf:knows
    // _:blankNodeWerner
    // <http://xmlns.com/foaf/0.1/knows>
    // _:blankNodeMax.
    model.addStatement(werner, foafKnows, max);
   
    // default dump
    DumpUtils.dump(model, null);
   
    // queries
    // get all persons
   
    ClosableIterator<? extends Statement> it = model.findStatements(Variable.ANY, RDF.type,
            foafPerson);
    while(it.hasNext()) {
      Resource person = it.next().getSubject();
      System.out.println(person + " is a person");
     
      // get foaf:name
      ClosableIterator<? extends Statement> it2 = model.findStatements(person, foafName,
              Variable.ANY);
      while(it2.hasNext()) {
        System.out.println(person + " has the foaf:name " + it2.next().getObject());
      }
    }
View Full Code Here

    // let it create a model
    // check if the model is closed by default
    // and truly open if it was opened
    ModelFactory modelFactory = RDF2Go.getModelFactory();
    Assert.assertNotNull(modelFactory);
    Model model = modelFactory.createModel();
    Assert.assertNotNull(model);
    Assert.assertFalse(model.isOpen());
    model.open();
    Assert.assertTrue(model.isOpen());
   
    // use the model a bit
    // load foaf test data
    // make sure the file is loaded
    // assure the model form above has no entries
    // put the foaf file into the model and make sure the model now
    // has elements
    // finally close the model and find out if it truly is closed
    InputStream foafStream = TestData.getFoafAsStream();
    Assert.assertNotNull(foafStream);
    Assert.assertEquals(0, model.size());
    model.readFrom(foafStream);
    Assert.assertTrue(model.size() > 0);
    model.close();
    Assert.assertFalse(model.isOpen());
  }
View Full Code Here

    return new HashSet<String>();
  }
 
  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws ModelRuntimeException {
    Model m = new ModelImplJena26(Reasoning.rdfs);
    URI u = RDF.Bag;
    URI p = RDF.type;
    @SuppressWarnings("unused")
    HashSet<String> names = (HashSet<String>)getAllValues(m, u, p, String.class);
  }
View Full Code Here

    log.debug("query = " + query);
  }

  @Test
  public void testApplyRule() {
    Model m = RDF2Go.getModelFactory().createModel();
    m.open();
    Map<String, URI> nsMap = new HashMap<String, URI>();
    nsMap.put("rdf", new URIImpl(
        "http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
    String LOCAL = "http://example.com#";
    nsMap.put("", new URIImpl(LOCAL));
    URI a = new URIImpl(LOCAL + "a");
    URI b = new URIImpl(LOCAL + "b");
    URI c = new URIImpl(LOCAL + "c");

    m.addStatement(a, b, c);
    m.addStatement(a, RDF.type, c);
    log.debug("Before");
    m.dump();

    String constructRemove = "?x a " + c.toSPARQL();
    String constructAdd = "?x a " + b.toSPARQL();
    String where = constructRemove;

    SearchRemoveAddRule.searchAndReplace(m, nsMap, where, constructRemove,
        constructAdd);
    log.debug("After");
    m.dump();
  }
View Full Code Here

    m.dump();
  }

  @Test
  public void testUriRename() {
    Model m = RDF2Go.getModelFactory().createModel();
    m.open();

    URI a = new URIImpl("urn:test:a");
    URI b = new URIImpl("urn:test:b");
    URI c = new URIImpl("urn:test:c");

    URI superRel = new URIImpl(
        "http://www.semanticdesktop.org/ontologies/2007/09/cds/hasSuperRelation");
    m.addStatement(superRel, b, c);
    m.addStatement(a, superRel, c);
    m.addStatement(a, b, superRel);
    Map<String, URI> nsMap = new HashMap<String, URI>();
    URISearchReplaceRule.searchAndReplace(m, nsMap, superRel,
        RDFS.subPropertyOf);

    m.dump();
    Assert.assertFalse(m.contains(superRel, Variable.ANY, Variable.ANY));
  }
View Full Code Here

    Assert.assertFalse(m.contains(superRel, Variable.ANY, Variable.ANY));
  }

  @Test
  public void testUriPrefixRename() {
    Model m = RDF2Go.getModelFactory().createModel();
    m.open();

    URI a = new URIImpl("urn:test:a");
    URI b = new URIImpl("urn:test:b");
    URI c = new URIImpl("urn:test:c");

    URI superRel = new URIImpl(
        "http://www.semanticdesktop.org/ontologies/2007/09/cds/hasSuperRelation");
    m.addStatement(superRel, b, c);
    m.addStatement(a, superRel, c);
    m.addStatement(a, b, superRel);
    NamespaceSearchReplaceRule.searchAndReplace(m, "urn:test:", "http://example.com#");
   
    m.dump();
    Assert.assertFalse(m.contains(a, Variable.ANY, Variable.ANY));
  }
View Full Code Here

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

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

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

    if (jenaQuery.isConstructType()) {
      com.hp.hpl.jena.rdf.model.Model m = qexec.execConstruct();
      Model resultModel = new ModelImplJena(null, m, Reasoning.none);
      resultModel.open();
      return resultModel;
    } else {
      throw new RuntimeException(
          "Cannot handle this type of query! Please use CONSTRUCT.");
    }
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.