Package org.openrdf.model

Examples of org.openrdf.model.Graph


   * @param _uris
   * @param inGraph
   * @param outGraph
   */
  public static void loadResources(Value[] _uris, LocalRepository inGraph, Graph outGraph) {
    Graph g;
    for(Value vuri : _uris) {
      String _uri = (vuri instanceof BNode)?("_:"+((BNode)vuri).getID()):("<"+vuri.toString()+">");
      Repository.logger.info("Load: "+_uri+"|"+RDFQuery.RDFQ_ACCESS_RESOURCE.toString(_uri));
      g = SesameWrapper.performGraphQuery(inGraph, QueryLanguage.SERQL, RDFQuery.RDFQ_ACCESS_RESOURCE.toString(_uri));
      if(g != null)
View Full Code Here


      Value action = aaction[0];
     
      //1. load info about the action
      String squery = RDFQuery.RDFQ_GET_ACTION_IN_CONTEXT.toString(action);
     
      Graph g2 = SesameWrapper.performGraphQuery(Repository.MAIN_REPOSITORY.getLocalRepository(),
                             QueryLanguage.SERQL, squery);     
      try {
        lr.addGraph(g2);

        //2. compute the path
View Full Code Here

  protected void computerPath(Graph g, Value action, List<Integer> _usedPath) throws AccessDeniedException {
    Value axis = null;
    Value newaction = action;
    StatementIterator it;
    Set<Value> antiloop = new HashSet<Value>();
    Graph globalGraph = Repository.MAIN_REPOSITORY.getLocalRepository().getGraph();

    while(newaction != null) {
      if(newaction instanceof Resource && !antiloop.contains(newaction)) {
        antiloop.add(newaction);

        it = globalGraph.getStatements((Resource)newaction, MultiBeeBrowseRDF.MBB_FOLLOWSALONGAXIS.getURI(g), null);
       
        if(it != null && it.hasNext()) {
          axis = it.next().getObject();
       
          it = globalGraph.getStatements((Resource)newaction, MultiBeeBrowseRDF.MBB_FOLLOWS.getURI(g), null);
         
          if(it != null && it.hasNext())
            newaction = it.next().getObject();
       
          if(axis instanceof Literal)
View Full Code Here

        // "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone Device\"}}";
        final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
        final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
        final Object input = JsonUtils.fromString(inputstring);

        final Graph graph = new LinkedHashModel();
        final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
        final ParserConfig parserConfig = new ParserConfig();
        final SesameTripleCallback callback = new SesameTripleCallback(
                new StatementCollector(graph), ValueFactoryImpl.getInstance(), parserConfig,
                parseErrorListener);

        JsonLdProcessor.toRDF(input, callback);

        final Iterator<Statement> statements = graph.iterator();

        // contains only one statement (type)
        while (statements.hasNext()) {
            final Statement stmt = statements.next();
View Full Code Here

   * Convert the Jena Model to a Sesame Graph
   * @param theModel the model to convert
   * @return the set of statements in the Jena model saved in a sesame Graph
   */
  public static Graph asSesameGraph(Model theModel) {
    Graph aGraph = new GraphImpl();

    StmtIterator sIter = theModel.listStatements();
    while (sIter.hasNext()) {
      aGraph.add(asSesameStatement(sIter.nextStatement()));
    }

    sIter.close();

    return aGraph;
View Full Code Here

    String aSeRQL = "construct {s} p {o}\n" +
             (aNG == null ? "from\n" : "from context <" + aNG + ">\n") +
             "{s} p {o} where s = " + aDialect.asQueryString(aResource) + "";

    Graph aGraph;

    if (theSource.getQueryFactory().getDialect() instanceof SerqlDialect) {
      aGraph = theSource.graphQuery(aSeRQL);
    }
    else {
View Full Code Here

   * @param theData the data to be filtered
   * @return a graph that contains only triples that do not exist in the data source
   * @throws DataSourceException if querying the data source causes an error
   */
  private Graph nonExistingTriples(Graph theData) throws DataSourceException {
    Graph aResult = Graphs.newGraph();
   
    // TODO: is there a more efficient way to check that than triple-by-triple?
    // (for remote data sources this will cause one request for triple ...)
    for (Iterator<Statement> it = theData.iterator(); it.hasNext(); ) {
      Statement statement = it.next();
     
      if (!existsInDataSource(statement)) {
        aResult.add(statement);
      }
    }
   
    return aResult;
  }
View Full Code Here

   * @param theData the data to be filtered
   * @return a graph that contains only triples that already exist in the data source
   * @throws DataSourceException if querying the data source causes an error
   */
  private Graph existingTriples(Graph theData) throws DataSourceException {
    Graph aResult = Graphs.newGraph();

    // TODO: is there a more efficient way to check that than triple-by-triple?
    // (for remote data sources this will cause one request for triple ...)
    for (Iterator<Statement> it = theData.iterator(); it.hasNext(); ) {
      Statement statement = it.next();
     
      if (existsInDataSource(statement)) {
        aResult.add(statement);
      }
    }
   
    return aResult;
  }
View Full Code Here

      boolean isTopOperation = (mOp == null);

      DataSourceOperation aOp = new DataSourceOperation();

      Graph aData = RdfGenerator.asRdf(theObj);

      if (doesSupportNamedGraphs() && EmpireUtil.hasNamedGraphSpecified(theObj)) {
        aOp.add(EmpireUtil.getNamedGraph(theObj), aData);
      }
      else {
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public <T> T merge(final T theT) {
    assertStateOk(theT);

    Graph aExistingData = null;
   
    if (theT instanceof EmpireGenerated) {
      aExistingData = ((EmpireGenerated) theT).getInstanceTriples();
    }

    if (aExistingData == null || aExistingData.isEmpty()) {
      // it looks like this bean instance does not have instance triples set properly (for some reason)
      // if we assume that aExistingData is empty, then no triples will be removed in the try/catch section below,
      // which can lead to duplicate triples

      // while in ideal world, this situation should not occur, below is an attempt to alleviate the case (i.e.,
      // find out what the instance triples actually are)
      try {
        if (theT instanceof EmpireGenerated) {
          // if bean has been generated by Empire, then we can try to read its copy from the database, and use the triples from that copy
          Object aDbObj = find(((EmpireGenerated) theT).getInterfaceClass(), EmpireUtil.asSupportsRdfId(theT).getRdfId());

          if (aDbObj != null) {
            aExistingData = ((EmpireGenerated) aDbObj).getInstanceTriples();
          }
          else {
            aExistingData = new GraphImpl();
          }
        }
        else {
          // as a fall back, we can perform a describe to find all related triples for the individual;
          // unfortunately, describe returns more information (in fact, it probably gives us more what getAllTriples() would return
          // rather than getInstanceTriples()), but there is not much else we can do
          aExistingData = assertContainsAndDescribe(theT);
        }
      }
      catch (IllegalArgumentException e) {
        // when everything else fails, just assume that existing data was indeed empty ...
        aExistingData = new GraphImpl();
      }
    }

    try {
      preUpdate(theT);

      Graph aData = RdfGenerator.asRdf(theT);

      boolean isTopOperation = (mOp == null);

      DataSourceOperation aOp = new DataSourceOperation();

View Full Code Here

TOP

Related Classes of org.openrdf.model.Graph

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.