Package de.fuberlin.wiwiss.d2rq.jena

Examples of de.fuberlin.wiwiss.d2rq.jena.ModelD2RQ


    return mapping;
  }

  public ModelD2RQ getModelD2RQ() {
    if (dataModel == null) {
      dataModel = new ModelD2RQ(getMapping());
    }
    return dataModel;
  }
View Full Code Here


import de.fuberlin.wiwiss.d2rq.jena.ModelD2RQ;

public class SPARQLExample {

  public static void main(String[] args) {
    ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
    String sparql =
      "PREFIX dc: <http://purl.org/dc/elements/1.1/>" +
      "PREFIX foaf: <http://xmlns.com/foaf/0.1/>" +
      "SELECT ?paperTitle ?authorName WHERE {" +
      "    ?paper dc:title ?paperTitle . " +
      "    ?paper dc:creator ?author ." +
      "    ?author foaf:name ?authorName ." +
      "}";
    Query q = QueryFactory.create(sparql);
    ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
    while (rs.hasNext()) {
      QuerySolution row = rs.nextSolution();
      System.out.println("Title: " + row.getLiteral("paperTitle").getString());
      System.out.println("Author: " + row.getLiteral("authorName").getString());
    }
    m.close();
  }
View Full Code Here

      if (!stmt.getObject().isURIResource()) {
        throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:resourceBaseURI must be a URI");
      }
      resourceBaseURI = ((Resource) stmt.getObject()).getURI();
    }
    return new ModelD2RQ(mappingFileURI, null, resourceBaseURI);
  }
View Full Code Here

  }
 
  protected abstract String mapURL();
 
  protected void setUp() throws Exception {
    this.model = new ModelD2RQ(mapURL(), "TURTLE", "http://test/");
//    this.model.enableDebug();
      setUpShowErrors(); // should be activated all the time
//      setUpShowPerformance(); // activate (only) to test performance (only)
      //setUpShowStatements(); // activate to analyse generated SQL statements
      //setUpMixOutputs(true); // activate to mix output from two QueryHandlers nicely
View Full Code Here

    private GraphD2RQ graph;
  private Set<Triple> resultTriples;

  protected void setUp() throws Exception {
    this.graph = (GraphD2RQ) new ModelD2RQ(D2RQTestSuite.ISWC_MAP, "TURTLE", "http://test/").getGraph();
  }
View Full Code Here

            + cmd.getArg(timeoutArg).getValue() + "'", D2RQException.MUST_BE_NUMERIC);
      }
    }
   
    loader.setFastMode(true);
    ModelD2RQ d2rqModel = loader.getModelD2RQ();

    String prefixes = "";
    for (String prefix: d2rqModel.getNsPrefixMap().keySet()) {
      prefixes += "PREFIX " + prefix + ": <" + d2rqModel.getNsPrefixURI(prefix) + ">\n";
    }
    query = prefixes + query;
    log.info("Query:\n" + query);
   
    try {
      QueryEngineD2RQ.register();
      Query q = QueryFactory.create(query, loader.getResourceBaseURI());
      QueryExecution qe = QueryExecutionFactory.create(q, d2rqModel);
      if (timeout > 0) {
        qe.setTimeout(Math.round(timeout * 1000));
      }
      QueryExecUtils.executeQuery(q, qe, ResultsFormat.lookup(format));
    } catch(QueryCancelledException ex) {
      throw new D2RQException("Query timeout", ex, D2RQException.QUERY_TIMEOUT);
    } finally {
      d2rqModel.close();
    }
  }
View Full Code Here

public class JenaModelExample {
 
  public static void main(String[] args) {
    // Set up the ModelD2RQ using a mapping file
    ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
   
    // Find anything with an rdf:type of iswc:InProceedings
    StmtIterator paperIt = m.listStatements(null, RDF.type, ISWC.InProceedings);
   
    // List found papers and print their titles
    while (paperIt.hasNext()) {
      Resource paper = paperIt.nextStatement().getSubject();
      System.out.println("Paper: " + paper.getProperty(DC.title).getString());
     
      // List authors of the paper and print their names
      StmtIterator authorIt = paper.listProperties(DC.creator);
      while (authorIt.hasNext()) {
        Resource author = authorIt.nextStatement().getResource();
        System.out.println("Author: " + author.getProperty(FOAF.name).getString());
      }
      System.out.println();
    }
    m.close();
  }
View Full Code Here

import junit.framework.TestCase;

public class JenaAPITest extends TestCase {

  public void testCopyPrefixesFromMapModelToD2RQModel() {
    ModelD2RQ m = new ModelD2RQ(D2RQTestSuite.DIRECTORY_URL + "prefixes.ttl");
    assertEquals("http://example.org/", m.getNsPrefixURI("ex"));
  }
View Full Code Here

    ModelD2RQ m = new ModelD2RQ(D2RQTestSuite.DIRECTORY_URL + "prefixes.ttl");
    assertEquals("http://example.org/", m.getNsPrefixURI("ex"));
  }
 
  public void testCopyPrefixesFromMapModelToD2RQGraph() {
    GraphD2RQ g = new ModelD2RQ(
        FileManager.get().loadModel(D2RQTestSuite.DIRECTORY_URL + "prefixes.ttl"), null).getGraph();
    assertEquals("http://example.org/", g.getPrefixMapping().getNsPrefixURI("ex"));
  }
View Full Code Here

        FileManager.get().loadModel(D2RQTestSuite.DIRECTORY_URL + "prefixes.ttl"), null).getGraph();
    assertEquals("http://example.org/", g.getPrefixMapping().getNsPrefixURI("ex"));
  }
 
  public void testDontCopyD2RQPrefixFromMapModel() {
    ModelD2RQ m = new ModelD2RQ(D2RQTestSuite.DIRECTORY_URL + "prefixes.ttl");
    assertNull(m.getNsPrefixURI("d2rq"));
  }
View Full Code Here

TOP

Related Classes of de.fuberlin.wiwiss.d2rq.jena.ModelD2RQ

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.