Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2012-2013 the Semargl contributors. See AUTHORS for more details. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.semarglproject.clerezza.core.sink;
 
 
 import java.util.Map;

Implementation if org.semarglproject.sink.TripleSink which feeds triples from Semargl's pipeline to Clerezza's org.apache.clerezza.rdf.core.MGraph.

List of supported options:

 
 public class ClerezzaSink implements TripleSink {
 
     public static final String OUTPUT_GRAPH_PROPERTY = "http://semarglproject.org/clerezza/properties/output-graph";
 
     protected MGraph graph;
     private final Map<StringBNodebnodeMap;
 
     protected ClerezzaSink(MGraph graph) {
         this. = graph;
          = new HashMap<StringBNode>();
     }

    
Instantiates sink for specified Clerezza org.apache.clerezza.rdf.core.MGraph

Parameters:
graph graph to sink triples to
Returns:
new instance of Clerezza sink
 
     public static TripleSink connect(MGraph graph) {
         return new ClerezzaSink(graph);
     }
 
     private BNode getBNode(String bnode) {
         if (!.containsKey(bnode)) {
             .put(bnodenew BNode());
         }
         return .get(bnode);
     }
 
     private NonLiteral convertNonLiteral(String arg) {
         if (arg.startsWith(.)) {
             return getBNode(arg);
         }
         return new UriRef(arg);
     }
 
     @Override
     public final void addNonLiteral(String subjString predString obj) {
         addTriple(convertNonLiteral(subj), new UriRef(pred), convertNonLiteral(obj));
     }
 
     @Override
     public final void addPlainLiteral(String subjString predString contentString lang) {
         Literal lit;
         if (lang == null || lang.equals("")) {
             lit = new PlainLiteralImpl(content);
         } else {
             lit = new PlainLiteralImpl(contentnew Language(lang));
         }
         addTriple(convertNonLiteral(subj), new UriRef(pred), lit);
     }
 
     @Override
     public final void addTypedLiteral(String subjString predString contentString type) {
         addTriple(convertNonLiteral(subj), new UriRef(pred),
                 new TypedLiteralImpl(contentnew UriRef(type)));
     }
    @Override
    public boolean setProperty(String keyObject value) {
        if (.equals(key) && value instanceof MGraph) {
             = (MGraphvalue;
            return true;
        }
        return false;
    }

    
Callback method for handling Clerezza triples.

Parameters:
subj triple's subject
pred triple's predicate
obj triple's object
    protected void addTriple(NonLiteral subjUriRef predResource obj) {
        .add(new TripleImpl(subjpredobj));
    }
    @Override
    public void startStream() throws ParseException {
    }
    @Override
    public void endStream() throws ParseException {
    }
    @Override
    public void setBaseUri(String baseUri) {
    }
New to GrepCode? Check out our FAQ X