Package org.openrdf.repository

Examples of org.openrdf.repository.RepositoryConnection


              Lens[] sublens = fd.getLenses(pdp.sublens);
   
              // Target resource is object from original
              // resource : fresnel:property : object statements
            try {
              RepositoryConnection connection = dataRepo.getConnection();
              RepositoryResult<Statement> msl = connection.getStatements(r, null, null, true);
              Statement sr;
              while (msl.hasNext()){
                sr = msl.next();
                URI pr = sr.getPredicate();
                if (pr.toString().equals(pdp.property)) {
View Full Code Here


    return null;
 
 
  private List<String> getResourceType(Repository repository, String r){
    List<String> list = new ArrayList<String>();
    RepositoryConnection con = null;
    try {
      con = repository.getConnection();
     
      if (con!=null) {
        try {
         
          String query = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT * WHERE {<"+r+"> rdf:type ?o }";
 
          TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
 
          TupleQueryResult result = tupleQuery.evaluate();
          try {
            String firstBindingName = result.getBindingNames().get(0);
            while (result.hasNext()) {
              Value uri = result.next().getBinding(firstBindingName).getValue();
              if (uri instanceof URI) {
                list.add(uri.toString());
              }
            }
          } finally {
            result.close();
          }
        } catch (QueryEvaluationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MalformedQueryException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } catch (RepositoryException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (con!=null)
        try {
          con.close();
        } catch (RepositoryException e) {
        // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }
View Full Code Here

  public String getClasses(String location, String meta) throws UnsupportedEncodingException {
    System.out.println("Loading Classes...");
    String out = "";
    String dataLocation = "";
    String dataMeta = "";
    RepositoryConnection con=null;
    try {

      if (location == "local") {
        out = "<div id='lensesAndClasses'><h3>Local Classes: </h3><hr><menu id='lclasses'>";       
        con=lenaConfig.getLocalRepository().getConnection();
        dataLocation = "&location=local";       
      } else if (location=="remote"){
        out = "<div id='lensesAndClasses'><h3>Remote Classes: </h3><hr><menu id='rclasses'>";
        con=lenaConfig.getRemoteRepository().getConnection();
        dataLocation = "&location=remote";
      }
      if (meta.equalsIgnoreCase("true")) {     
        dataMeta = "&meta=true";
      } else if (meta.equalsIgnoreCase("false")){
        dataMeta = "&meta=false";
      }
      if (con!=null) {
        try {
          String query = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT ?o WHERE { ?s rdf:type ?o } ORDER BY ?o";
 
          TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
 
          TupleQueryResult result = tupleQuery.evaluate();
          try {
            String firstBindingName = result.getBindingNames().get(0);
            while (result.hasNext()) {
              Value uri = result.next().getBinding(firstBindingName).getValue();
              if ((uri instanceof URI) &&
                (!uri.toString().contains("http://www.w3.org/2004/03/trix"))){
             
                String uriString = uri.toString();               
                String classInfo = getClassInfo(uriString, location);
                String before = "";
                String after = "";
 
                /*
                if (uriString == resource) {
                  before = "<b>";
                  after = "</b>";
                }*/
 
                if (uriString.lastIndexOf("#") == -1) {
                  out = out.concat("<li><a onClick='setHrefs()' class='tooltip' title='::" + uriString + "' href='?class="
                      + URLEncoder.encode(uriString, "UTF-8") + dataLocation + dataMeta +"'>" + before
                      + uriString.subSequence(uriString.lastIndexOf("/") + 1, uriString.length()) + " " + classInfo + after + "</a></li>");
                } else {
                  out = out.concat("<li><a onClick='setHrefs()' class='tooltip' title='::" + uriString + "' href='?class="
                      + URLEncoder.encode(uriString, "UTF-8") + dataLocation + dataMeta +"'>" + before
                      + uriString.subSequence(uriString.lastIndexOf("#") + 1, uriString.length()) + " " + classInfo + after + "</a></li>");
                }
              }
            }
          } finally {
            result.close();
          }
        } catch (QueryEvaluationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MalformedQueryException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } catch (RepositoryException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (con!=null)
        try {
          con.close();
        } catch (RepositoryException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }
View Full Code Here

   */
  public String getClassInfo(String uri, String location) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    String out = "";
    boolean isLensAvailable = false;
    int i = 0;
    RepositoryConnection con=null;
    Repository repository=null;

    if (location == "remote") {
      repository =lenaConfig.getRemoteRepository();
      con = repository.getConnection();
    } else if (location == "local") {
      repository = lenaConfig.getLocalRepository();
      con = repository.getConnection();
    }
    try {

      String query = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s WHERE { ?s rdf:type <" + uri + "> }";

      TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
      TupleQueryResult result = tupleQuery.evaluate();

      try {

        String firstBindingName = result.getBindingNames().get(0);
        while (result.hasNext()) {
         
          Value instance = result.next().getBinding(firstBindingName).getValue();
          //if (instance instanceof Resource) {           
            //if (isLensForResourceAvailable(((Resource) instance).stringValue(),location)) {
              //isLensAvailable = true;
            //}           
          //}
          i++;
        }
      } finally {
        result.close();
      }
    } finally {
      con.close();
    }
    int numberOfResources = 0;
    //NEW: Metaknowledge counts as instance. Take them out
    /*if(lenaConfig.getMetaknowledge())
      numberOfResources = i/2;
View Full Code Here

    org.w3c.dom.Document doc;
    try {
      /* Set up the repository that contains Fresnel lenses and formats */
      fresnelRepository = new SailRepository(new MemoryStore());
        fresnelRepository.initialize();
        RepositoryConnection fresnelConnection = fresnelRepository.getConnection();
       
       
        FresnelSesameParser fp = new FresnelSesameParser();
        File lensFile= new File(TEST_FRESNEL_PROGRAM_FILE_NAME);
      fd = fp.parse(lensFile, Constants.N3_READER);
     
        File fresnelFile = new File(TEST_FRESNEL_PROGRAM_FILE_NAME);
        fresnelConnection.add(fresnelFile, fresnelFile.toURL().toString(), RDFFormat.N3);
      /* Set up the repository that contains RDF data */
      dataRepository = new SailRepository(new MemoryStore());
      dataRepository.initialize();
      RepositoryConnection dataConnection = dataRepository.getConnection();
      File dataFile = new File(FOAF_PLANET_TEST_MODEL_FILE);
        dataConnection.add(dataFile, dataFile.toURL().toString(), RDFFormat.TRIX);
     
        //doc = renderer.render(fd, dataRepository, "http://isweb/RSS_planetRDF");
        doc = renderer.render(fd, dataRepository, "http://isweb/FOAF_person");
     
     
View Full Code Here

    org.w3c.dom.Document doc;
    try {
      /* Set up the repository that contains Fresnel lenses and formats */
      fresnelRepository = new SailRepository(new MemoryStore());
        fresnelRepository.initialize();
        RepositoryConnection fresnelConnection = fresnelRepository.getConnection();
        File fresnelFile = new File(TEST_FRESNEL_PROGRAM_FILE_NAME);
        fresnelConnection.add(fresnelFile, fresnelFile.toURL().toString(), RDFFormat.N3);
      /* Set up the repository that contains RDF data */
      dataRepository = new SailRepository(new MemoryStore());
      dataRepository.initialize();
      RepositoryConnection dataConnection = dataRepository.getConnection();
      File dataFile = new File(FOAF_TEST_MODEL_FILE);
        dataConnection.add(dataFile, dataFile.toURL().toString(), RDFFormat.RDFXML);
     
      doc = renderer.render(fresnelRepository, "", dataRepository);
     
      if (outputFDLFile != null) {
        StreamResult res = new StreamResult(new File(outputFDLFile));
View Full Code Here

    org.w3c.dom.Document doc;
    try {
      /* Set up the repository that contains Fresnel lenses and formats */
      fresnelRepository = new SailRepository(new MemoryStore());
        fresnelRepository.initialize();
        RepositoryConnection fresnelConnection = fresnelRepository.getConnection();
       
       
        FresnelSesameParser fp = new FresnelSesameParser();
        File lensFile= new File(TEST_FRESNEL_PROGRAM_FILE_NAME);
      fd = fp.parse(lensFile, Constants.N3_READER);
     
        File fresnelFile = new File(TEST_FRESNEL_PROGRAM_FILE_NAME);
        fresnelConnection.add(fresnelFile, fresnelFile.toURL().toString(), RDFFormat.N3);
      /* Set up the repository that contains RDF data */
      dataRepository = new SailRepository(new MemoryStore());
      dataRepository.initialize();
      RepositoryConnection dataConnection = dataRepository.getConnection();
      File dataFile1 = new File(FOAF_TEST_MODEL_FILE);
        dataConnection.add(dataFile1, dataFile1.toURL().toString(), RDFFormat.RDFXML);
     
        File dataFile2 = new File(PLANET_TEST_MODEL_FILE);
        dataConnection.add(dataFile2, dataFile2.toURL().toString(), RDFFormat.RDFXML);
      doc = renderer.render(fd, dataRepository, "http://isweb/RSS_planetRDF");
     
     
      if (outputFDLFile != null) {
        StreamResult res = new StreamResult(new File(outputFDLFile));
View Full Code Here

     * @return all objects of triples with matching subject and property
     */
    @Override
    public Collection<Value> listObjects(Value subject, Value property) {
        try {
            RepositoryConnection connection = repository.getConnection();

            try {
              connection.begin();
              return listObjectsInternal(connection, (Resource) subject, (org.openrdf.model.URI) property);
            } finally {
                connection.commit();
                connection.close();
            }
        } catch (RepositoryException e) {
            throw new RuntimeException("error while querying Sesame repository!",e);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException(String.format(
View Full Code Here

     * @throws UnsupportedOperationException in case reverse selection is not supported (e.g. when querying Linked Data)
     */
    @Override
    public Collection<Value> listSubjects(Value property, Value object) {
        try {
            final RepositoryConnection connection = repository.getConnection();

            try {
              connection.begin();
              return listSubjectsInternal(connection, (org.openrdf.model.URI) property, object);
            } finally {
                connection.commit();
                connection.close();
            }
        } catch (RepositoryException e) {
            throw new RuntimeException("error while querying Sesame repository!",e);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException(String.format(
View Full Code Here

                        Date expiresDate = new Date(System.currentTimeMillis()+defaultExpires*1000);
                        result.setExpires(expiresDate);
                    }

                    if(log.isInfoEnabled()) {
                        RepositoryConnection con = triples.getConnection();
                        log.info("retrieved {} triples for resource {}; expiry date: {}",new Object[] {con.size(),resource.stringValue(),result.getExpires()});
                        con.close();
                    }

                    return result;
                } finally {
                    in.close();
View Full Code Here

TOP

Related Classes of org.openrdf.repository.RepositoryConnection

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.