Package org.openrdf.model

Examples of org.openrdf.model.ValueFactory


    private void serializePropertyTypes( final EntityDescriptor entityDescriptor,
                                         final Graph graph,
                                         final URI entityTypeUri )
    {
        ValueFactory values = graph.getValueFactory();

        // Properties
        for( PropertyDescriptor persistentProperty : entityDescriptor.state().properties() )
        {
            URI propertyURI = values.createURI( persistentProperty.qualifiedName().toURI() );
            graph.add( propertyURI, Rdfs.DOMAIN, entityTypeUri );
            graph.add( propertyURI, Rdfs.TYPE, Rdfs.PROPERTY );

            // TODO Support more types
            URI type = dataTypes.get( persistentProperty.valueType().mainType().getName() );
View Full Code Here


   * @throws GraphException
   */
    public synchronized URI addElement(KeywordBean keyword) throws IOException, AccessDeniedException, GraphException {
        Graph myGraph = new org.openrdf.model.impl.GraphImpl();

        ValueFactory myFactory = myGraph.getValueFactory();

        // Define namespace
        String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
        String namespaceGml = "http://www.opengis.net/gml#";
        String namespace = keyword.getNameSpaceCode();

        if(namespace.equals("#")) {
          namespace = this.defaultNamespace;
        }
       
        // Create subject
        URI mySubject = myFactory.createURI(keyword.getUriCode());

        URI skosClass = myFactory.createURI(namespaceSkos, "Concept");
        URI rdfType = myFactory.createURI(org.openrdf.vocabulary.RDF.TYPE);
        URI predicatePrefLabel = myFactory
                .createURI(namespaceSkos, "prefLabel");
        URI predicateScopeNote = myFactory
                .createURI(namespaceSkos, "scopeNote");

        URI predicateBoundedBy = myFactory.createURI(namespaceGml, "BoundedBy");
        URI predicateEnvelope = myFactory.createURI(namespaceGml, "Envelope");
        URI predicateSrsName = myFactory.createURI(namespaceGml, "srsName");
        URI srsNameURI = myFactory
                .createURI("http://www.opengis.net/gml/srs/epsg.xml#epsg:4326");
        BNode gmlNode = myFactory.createBNode();
        URI predicateLowerCorner = myFactory.createURI(namespaceGml,
                "lowerCorner");
        URI predicateUpperCorner = myFactory.createURI(namespaceGml,
                "upperCorner");

        Literal lowerCorner = myFactory.createLiteral(keyword.getCoordWest() + " " + keyword.getCoordSouth());
        Literal upperCorner = myFactory.createLiteral(keyword.getCoordEast() + " " + keyword.getCoordNorth());

        mySubject.addProperty(rdfType, skosClass);
        Set<Entry<String, String>> values = keyword.getValues().entrySet();
        for (Entry<String, String> entry : values) {
            String language = toiso639_1_Lang(entry.getKey());
            Value valueObj = myFactory.createLiteral(entry.getValue(), language);
            myGraph.add(mySubject, predicatePrefLabel, valueObj );
           
        }
        Set<Entry<String, String>> definitions = keyword.getDefinitions().entrySet();
        for (Entry<String, String> entry : definitions) {
            String language = toiso639_1_Lang(entry.getKey());
            Value definitionObj = myFactory.createLiteral(entry.getValue(), language);
            myGraph.add(mySubject, predicateScopeNote, definitionObj );
           
        }
        myGraph.add(mySubject, predicateBoundedBy, gmlNode);

View Full Code Here

     * @param code
     * @throws AccessDeniedException
     */
    public synchronized Thesaurus removeElement(String namespace, String code) throws AccessDeniedException {
        Graph myGraph = repository.getGraph();
        ValueFactory myFactory = myGraph.getValueFactory();
        URI subject = myFactory.createURI(namespace, code);
       
        return removeElement(myGraph, subject);
    }
View Full Code Here

     * @param uri
     * @throws AccessDeniedException
     */
    public synchronized Thesaurus removeElement(String uri) throws AccessDeniedException {
        Graph myGraph = repository.getGraph();
        ValueFactory myFactory = myGraph.getValueFactory();
        URI subject = myFactory.createURI(uri);
       
        return removeElement(myGraph, subject);
    }
View Full Code Here

     
        // Get thesaurus graph
        Graph myGraph = repository.getGraph();     
       
        // Set namespace skos and predicates
        ValueFactory myFactory = myGraph.getValueFactory();
        String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
        URI predicatePrefLabel = myFactory .createURI(namespaceSkos, "prefLabel");
        URI predicateScopeNote = myFactory.createURI(namespaceSkos, "scopeNote");

        // Get subject (URI)
        URI subject = myFactory.createURI(keyword.getUriCode());

        // Remove old labels
        StatementIterator iter = myGraph.getStatements(subject, predicatePrefLabel, null);
        removeMatchingLiterals(replace, myGraph, iter, keyword.getValues().keySet());
       
        // remove old scopeNote
        iter = myGraph.getStatements(subject, predicateScopeNote, null);
        removeMatchingLiterals(replace, myGraph, iter, keyword.getDefinitions().keySet());

        // add updated Labels
        Set<Entry<String, String>> values = keyword.getValues().entrySet();
        for (Entry<String, String> entry : values) {
            String language = toiso639_1_Lang(entry.getKey());
            Value valueObj = myFactory.createLiteral(entry.getValue(), language);
            myGraph.add(subject, predicatePrefLabel, valueObj );
           
        }
        // add updated Definitions/Notes
        Set<Entry<String, String>> definitions = keyword.getDefinitions().entrySet();
        for (Entry<String, String> entry : definitions) {
            String language = toiso639_1_Lang(entry.getKey());
            Value definitionObj = myFactory.createLiteral(entry.getValue(), language);
            myGraph.add(subject, predicateScopeNote, definitionObj );
           
        }

      // update bbox
        if(replace || !(keyword.getCoordEast() + keyword.getCoordNorth() + keyword.getCoordWest() + keyword.getCoordSouth()).trim().isEmpty()) {
          String namespaceGml = "http://www.opengis.net/gml#";
          URI predicateBoundedBy = myFactory.createURI(namespaceGml, "BoundedBy");
          URI predicateLowerCorner = myFactory.createURI(namespaceGml, "lowerCorner");
          URI predicateUpperCorner = myFactory.createURI(namespaceGml, "upperCorner");
         
          BNode subjectGml = null;
          iter = myGraph.getStatements(subject, predicateBoundedBy, null);
          while (iter.hasNext()) {
              AtomicReference<Statement> st = new AtomicReference<Statement>(iter.next());
              if (st.get().getObject() instanceof BNode) {
                  subjectGml = (BNode) st.get().getObject();
              }
          }
          if (subjectGml != null) {
              // lowerCorner
              iter = myGraph.getStatements(subjectGml, predicateLowerCorner, null);
              while (true) {
                  if (!(iter.hasNext())) {
                      break;
                  }
                  AtomicReference<Statement> st = new AtomicReference<Statement>(iter.next());
                  myGraph.remove(st.get());
                  break;
              }
              // upperCorner
              iter = myGraph.getStatements(subjectGml, predicateUpperCorner, null);
              while (true) {
                  if (!(iter.hasNext())) {
                      break;
                  }
                  AtomicReference<Statement> st = new AtomicReference<Statement>(iter.next());
                  myGraph.remove(st.get());
                  break;
              }
              // create the new statements
              Literal lowerCorner = myFactory.createLiteral(keyword.getCoordWest() + " " + keyword.getCoordSouth());
              Literal upperCorner = myFactory.createLiteral(keyword.getCoordEast() + " " + keyword.getCoordNorth());
             
              // Add the new statements
              myGraph.add(subjectGml, predicateLowerCorner, lowerCorner);
              myGraph.add(subjectGml, predicateUpperCorner, upperCorner);
          }
View Full Code Here

     * @throws AccessDeniedException
     */
  public synchronized boolean isFreeCode(String namespace, String code) throws AccessDeniedException {
    boolean res = true;       
    Graph myGraph = repository.getGraph();
    ValueFactory myFactory = myGraph.getValueFactory();
    URI obj = namespace == null ? myFactory.createURI(code) : myFactory.createURI(namespace,code);
    Collection<?> statementsCollection = myGraph.getStatementCollection(obj,null,null);
    if (statementsCollection!=null && statementsCollection.size()>0){
      res = false;
    }
    statementsCollection = myGraph.getStatementCollection(null,null,obj);
View Full Code Here

     * @throws IOException
     */
    public synchronized Thesaurus updateCode(String namespace, String oldcode, String newcode) throws AccessDeniedException, IOException {
      Graph myGraph = repository.getGraph();
   
    ValueFactory myFactory = myGraph.getValueFactory();

    URI oldobj = myFactory.createURI(namespace,oldcode);
    URI newobj = myFactory.createURI(namespace,newcode);
   
    return updateElementCode(myGraph, oldobj, newobj);
   
    }
View Full Code Here

     * @throws IOException
     */
  public synchronized Thesaurus updateCodeByURI(String olduri, String newuri) throws AccessDeniedException, IOException {
    Graph myGraph = repository.getGraph();
   
    ValueFactory myFactory = myGraph.getValueFactory();
   
    URI oldobj = myFactory.createURI(olduri);
    URI newobj = myFactory.createURI(newuri);
   
    return updateElementCode(myGraph, oldobj, newobj);
  }
View Full Code Here

     */
    public void addTitleElement(String thesaurusTitle) throws IOException, AccessDeniedException, GraphException{
     
      Graph myGraph = new org.openrdf.model.impl.GraphImpl();

      ValueFactory myFactory = myGraph.getValueFactory();
     
      String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
      String namespaceDC = "http://purl.org/dc/elements/1.1/";
     
      URI mySubject = myFactory.createURI( "http://geonetwork-opensource.org/" , thesaurusTitle);
      URI skosClass = myFactory.createURI(namespaceSkos, "ConceptScheme");
      URI titleURI = myFactory.createURI(namespaceDC, "title");
     
      URI rdfType = myFactory.createURI(org.openrdf.vocabulary.RDF.TYPE);
     
      mySubject.addProperty(rdfType, skosClass);
     
      Value valueObj = myFactory.createLiteral(thesaurusTitle);
      myGraph.add(mySubject, titleURI, valueObj );
     
      repository.addGraph(myGraph);
    }
View Full Code Here

        MalformedQueryException, QueryEvaluationException, GraphException {
           
            Graph myGraph = repository.getGraph();     
           
             // Set namespace skos and predicates
             ValueFactory myFactory = myGraph.getValueFactory();
             String namespaceSkos = "http://www.w3.org/2004/02/skos/core#";
             URI relationURI = myFactory .createURI(namespaceSkos, related.name);
             URI opposteRelationURI = myFactory .createURI(namespaceSkos, related.opposite().name);
             URI subjectURI = myFactory.createURI(subject);
             URI relatedSubjectURI = myFactory.createURI(relatedSubject);

             myGraph.add(subjectURI, relationURI, relatedSubjectURI);
             myGraph.add(relatedSubjectURI, opposteRelationURI, subjectURI);
        }
View Full Code Here

TOP

Related Classes of org.openrdf.model.ValueFactory

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.