Package org.openrdf.model

Examples of org.openrdf.model.Graph


    private SolrInputDocument indexEntityState( final EntityState entityState,
                                                final SolrServer server )
            throws IOException, SolrServerException, JSONException
    {
        Graph graph = new GraphImpl();
        stateSerializer.serialize( entityState, false, graph );

        SolrInputDocument input = new SolrInputDocument();
        input.addField( "id", entityState.identity().identity() );
        input.addField( "type", first(entityState.entityDescriptor().types()).getName() );
        input.addField( "lastModified", new Date( entityState.lastModified() ) );

        for( Statement statement : graph )
        {
            SchemaField field = indexedFields.get( statement.getPredicate().getLocalName() );
            if( field != null )
            {
                if( statement.getObject() instanceof Literal )
                {
                    String value = statement.getObject().stringValue();
                    if( field.getType().getTypeName().equals( "json" ) )
                    {
                        if( value.charAt( 0 ) == '[' )
                        {
                            JSONArray array = new JSONArray( value );
                            indexJson( input, array );
                        } else if( value.charAt( 0 ) == '{' )
                        {
                            JSONObject object = new JSONObject( value );
                            indexJson( input, object );
                        }
                    } else
                    {
                        input.addField( field.getName(), value );
                    }
                } else if( statement.getObject() instanceof URI && !"type".equals( field.getName() ) )
                {
                    String value = statement.getObject().stringValue();
                    value = value.substring( value.lastIndexOf( ':' ) + 1, value.length() );
                    String name = field.getName();
                    input.addField( name, value );
                } else if( statement.getObject() instanceof BNode )
                {
                    Iterator<Statement> seq = graph.match( (Resource) statement.getObject(), new URIImpl( "http://www.w3.org/1999/02/22-rdf-syntax-ns#li" ), null, (Resource) null );
                    while( seq.hasNext() )
                    {
                        Statement seqStatement = seq.next();
                        String value = seqStatement.getObject().stringValue();
                        value = value.substring( value.lastIndexOf( ':' ) + 1, value.length() );
View Full Code Here


    }

    public Iterable<Statement> serialize( final EntityState entityState,
                                          final boolean includeNonQueryable )
    {
        Graph graph = new GraphImpl();
        serialize( entityState, includeNonQueryable, graph );
        return graph;
    }
View Full Code Here

        dataTypes.put( LocalDate.class.getName(), XMLSchema.DATE );
    }

    public Iterable<Statement> serialize( final EntityDescriptor entityDescriptor )
    {
        Graph graph = new GraphImpl();
        ValueFactory values = graph.getValueFactory();
        URI entityTypeUri = values.createURI( Classes.toURI( first( entityDescriptor.types() ) ) );

        graph.add( entityTypeUri, Rdfs.TYPE, Rdfs.CLASS );
        graph.add( entityTypeUri, Rdfs.TYPE, OWL.CLASS );

        graph.add( entityTypeUri, Qi4jEntityType.TYPE, values.createLiteral( first( entityDescriptor.types() ).toString() ) );
        graph.add( entityTypeUri, Qi4jEntityType.QUERYABLE, values.createLiteral( entityDescriptor.queryable() ) );

        serializeMixinTypes( entityDescriptor, graph, entityTypeUri );

        serializePropertyTypes( entityDescriptor, graph, entityTypeUri );
        serializeAssociationTypes( entityDescriptor, graph, entityTypeUri );
View Full Code Here

public class ApplicationSerializer
{
    public Graph serialize( Application app )
    {
        Graph graph = new GraphImpl();
        SerializerContext context = new SerializerContext( graph );
        ApplicationVisitor applicationVisitor = new ApplicationVisitor( context );
        ( (Application) app ).descriptor().accept( applicationVisitor );
        return graph;
    }
View Full Code Here

   * @throws IOException
   * @throws AccessDeniedException
   * @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);

        gmlNode.addProperty(rdfType, predicateEnvelope);
        myGraph.add(gmlNode, predicateLowerCorner, lowerCorner);
        myGraph.add(gmlNode, predicateUpperCorner, upperCorner);
        myGraph.add(gmlNode, predicateSrsName, srsNameURI);

        repository.addGraph(myGraph);
        return mySubject;
    }
View Full Code Here

     * @param namespace
     * @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

   */
  public synchronized URI updateElement(KeywordBean keyword, boolean replace) throws AccessDeniedException, IOException,
          MalformedQueryException, QueryEvaluationException, GraphException {
     
        // 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);
          }
      }
       
        return subject;
  }
View Full Code Here

     * @return
     * @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);
    if (statementsCollection!=null && statementsCollection.size()>0){
      res = false;
    }       
    return res;
  }
View Full Code Here

     * @return
     * @throws AccessDeniedException
     * @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

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.