本文整理汇总了Java中org.apache.clerezza.rdf.core.TripleCollection类的典型用法代码示例。如果您正苦于以下问题:Java TripleCollection类的具体用法?Java TripleCollection怎么用?Java TripleCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TripleCollection类属于org.apache.clerezza.rdf.core包,在下文中一共展示了TripleCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
/**
* Performs the actual transformation mapping the data extracted from OSM XML data to a Clerezza graph.
* @return
*/
public TripleCollection transform(){
TripleCollection resultGraph = new SimpleMGraph();
processXmlBinary();
for(String wayId: osmWayNodeMap.keySet()) {
OsmWay wayObj = osmWayNodeMap.get(wayId);
UriRef wayUri = new UriRef("http://fusepoolp3.eu/osm/way/" + wayId);
resultGraph.add(new TripleImpl(wayUri, RDF.type, new UriRef("http://schema.org/PostalAddress")));
resultGraph.add(new TripleImpl(wayUri, new UriRef("http://schema.org/streetAddress"), new PlainLiteralImpl(wayObj.getTagName())));
UriRef geometryUri = new UriRef("http://fusepoolp3.eu/osm/geometry/" + wayId);
resultGraph.add(new TripleImpl(wayUri, new UriRef("http://www.opengis.net/ont/geosparql#geometry"), geometryUri));
String linestring = getWktLineString(wayObj.getNodeReferenceList());
resultGraph.add(new TripleImpl(geometryUri, new UriRef("http://www.opengis.net/ont/geosparql#asWKT"), new PlainLiteralImpl(linestring)));
}
return resultGraph;
}
示例2: testTransform
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
@Test
public void testTransform() throws IOException {
String osmDataUrl = RestAssured.baseURI + "/data/" + MOCK_OSM_SERVER_DATA ;
parser = new OsmXmlParser(osmDataUrl);
long startTime = System.currentTimeMillis();
System.out.println("transform() Start time: " + startTime);
TripleCollection graph = parser.transform();
Iterator<Triple> igraph = graph.iterator();
while(igraph.hasNext()){
Triple t = igraph.next();
System.out.println(t.getSubject() + " " + t.getPredicate() + " " + t.getObject());
}
long stopTime = System.currentTimeMillis();
System.out.println("transform() Stop time: " + stopTime);
double time = (stopTime - startTime) / 1000.0;
System.out.println("transform() Elapsed time: " + time + " sec." );
System.out.println();
}
示例3: hasValue
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
/**
* Checks if the value is parsed of the parsed triple filter.
* IMPARTANT: This method expects that exactly one of subject, predicate and
* object is <code>null</code>
* @param source the triple collection
* @param sub subject filter (<code>null</code> for wildcard)
* @param pred predicate filter (<code>null</code> for wildcard)
* @param obj Object filter (<code>null</code> for wildcard)
* @param value the value
* @return <code>true</code> if the parsed value is part of the triples selected
* by the parsed triple pattern.
*/
public boolean hasValue(TripleCollection source, NonLiteral sub, UriRef pred, Resource obj, Resource value){
if(value == null){
return false;
}
Iterator<Triple> it = source.filter(sub, pred, obj);
while(it.hasNext()){
Triple t = it.next();
Resource act = sub == null ? t.getSubject() : pred == null
? t.getPredicate() : t.getObject();
if(act.equals(value)){
return true;
}
}
return false;
}
示例4: assertOptValues
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private <T extends Resource> Set<T> assertOptValues(TripleCollection graph,
NonLiteral subject, UriRef property, Class<T> type) {
Iterator<Triple> it = graph.filter(subject, property, null);
if(!it.hasNext()){
return Collections.emptySet();
}
Set<T> values = new HashSet<T>();
while(it.hasNext()){
Resource value = it.next().getObject();
assertTrue(type.getSimpleName()+" expected but value "+ value +
" had the type "+value.getClass().getSimpleName()+"!",
type.isAssignableFrom(value.getClass()));
values.add(type.cast(value));
}
return values;
}
示例5: generateRdf
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
/**
* Get SIOC content from the RDF as text and return it.
*
* @param entity
* @return
* @throws IOException
*/
@Override
protected TripleCollection generateRdf(HttpRequestEntity entity) throws IOException {
String text = "";
Graph graph = Parser.getInstance().parse(entity.getData(), "text/turtle");
Iterator<Triple> triples = graph.filter(null, SIOC.content, null);
if (triples.hasNext()) {
Literal literal = (Literal) triples.next().getObject();
text = literal.getLexicalForm();
}
final TripleCollection result = new SimpleMGraph();
final Resource resource = entity.getContentLocation() == null
? new BNode()
: new UriRef(entity.getContentLocation().toString());
final GraphNode node = new GraphNode(resource, result);
node.addProperty(RDF.type, TEXUAL_CONTENT);
node.addPropertyValue(SIOC.content, text);
node.addPropertyValue(new UriRef("http://example.org/ontology#textLength"), text.length());
return result;
}
示例6: generateRdf
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
@Override
protected TripleCollection generateRdf(HttpRequestEntity entity) throws IOException {
String rdfDataFormat = SupportedFormat.TURTLE;
InputStream configIn = null;
String queryString = entity.getRequest().getQueryString();
log.info("Query string: " + queryString);
//String configUri = getRequestParamValue(queryString, "config");
String configUri = entity.getRequest().getParameter("config");
log.info("Config file URI: " + configUri);
if(configUri != null) {
configIn = getRemoteConfigFile(configUri);
}
final InputStream inputRdfData = entity.getData();
TripleCollection duplicates = findSameEntities(inputRdfData, rdfDataFormat, configIn);
return duplicates;
}
示例7: getPoint
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
/**
* Extracts one spatial point or event from the client data.
* @param graph
* @return
* @throws ParseException
*/
public WGS84Point getPoint(TripleCollection graph) {
WGS84Point point = new WGS84Point();
NonLiteral pointRef = graph.filter(null, geo_lat, null).next().getSubject();
String latitude = ( (TypedLiteral) graph.filter(pointRef, geo_lat, null).next().getObject() ).getLexicalForm();
String longitude = ( (TypedLiteral) graph.filter(pointRef, geo_long, null).next().getObject() ).getLexicalForm();
point.setUri(pointRef.toString());
point.setLat(Double.valueOf(latitude));
point.setLong(Double.valueOf(longitude));
// look for events linked to places
if(graph.filter(null, schema_startDate, null).hasNext()){
String startDate = ( (TypedLiteral) graph.filter(null, schema_startDate, null).next().getObject()).getLexicalForm();
String endDate = ( (TypedLiteral) graph.filter(null, schema_endDate, null).next().getObject()).getLexicalForm();
point.setStartDate(startDate);
point.setEndDate(endDate);
}
return point;
}
示例8: reconcileCommand
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
/**
* Reconciles a source graph with a target graph. The result of the
* reconciliation is an equivalence set stored in the interlink graph of the
* pipe. The graph used as source is the source rdf graph.
*/
private void reconcileCommand(DataSet dataSet, UriRef sourceGraphRef, UriRef targetGraphRef, String selectedInterlinker) {
if (graphExists(sourceGraphRef)) {
// Get the source graph from the triple store
LockableMGraph sourceGraph = dataSet.getSourceGraph();
// reconcile the source graph with the target graph
Interlinker interlinker = interlinkers.get(selectedInterlinker);
TripleCollection owlSameAs = interlinker.interlink(sourceGraph, targetGraphRef);
if (owlSameAs.size() > 0) {
LockableMGraph sameAsGraph = dataSet.getInterlinksGraph();
sameAsGraph.addAll(owlSameAs);
// add a reference of the equivalence set to the source graph
dlcGraphProvider.getDlcGraph().add(new TripleImpl(dataSet.getInterlinksGraphRef(), DLC.subjectsTarget, sourceGraphRef));
// add a reference of the equivalence set to the target graph
dlcGraphProvider.getDlcGraph().add(new TripleImpl(dataSet.getInterlinksGraphRef(), DLC.objectsTarget, targetGraphRef));
}
}
}
示例9: parse
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
@Override
public RDFDataset parse(Object input) throws JsonLdError {
count = 0;
final Map<BNode, String> bNodeMap = new HashMap<BNode, String>(1024);
final RDFDataset result = new RDFDataset();
if (input instanceof TripleCollection) {
for (final Triple t : ((TripleCollection) input)) {
handleStatement(result, t, bNodeMap);
}
}
bNodeMap.clear(); // help gc
return result;
}
示例10: getAddress
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private Address getAddress(TripleCollection inputGraph) {
Address addr = new Address();
Iterator<Triple> itriple = inputGraph.filter(null,schema_streetAddress,null);
while ( itriple.hasNext() ) {
Triple triple = itriple.next();
UriRef addressUri = (UriRef) triple.getSubject();
addr.setStreetAddress( ((PlainLiteralImpl) triple.getObject()).getLexicalForm() );
// get locality
Iterator<Triple> addresslocalityIter = inputGraph.filter(addressUri, schema_addressLocality, null) ;
if ( addresslocalityIter != null ) {
while ( addresslocalityIter.hasNext() ) {
String locality = ((PlainLiteralImpl) addresslocalityIter.next().getObject()).getLexicalForm();
if ( ! "".equals(locality) ) {
addr.setLocality( locality );
}
}
}
// get country code
Iterator<Triple> addressCountryIter = inputGraph.filter(addressUri, schema_addressCountry, null) ;
if ( addressCountryIter != null ) {
while ( addressCountryIter.hasNext() ) {
String countryCode = ((PlainLiteralImpl) addressCountryIter.next().getObject()).getLexicalForm();
if ( ! "".equals( countryCode ) ) {
addr.setCountryCode( countryCode );
}
}
}
}
return addr;
}
示例11: assertOASelector
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private void assertOASelector(ContentItem contentItem, UriRef selector){
TripleCollection graph = contentItem.getMetadata();
Set<UriRef> types = assertHasValues(graph, selector, RDF_TYPE, UriRef.class);
assertTrue(types.contains(OA_TEXT_POSITION_SELECTOR));
assertTrue(types.contains(OA_TEXT_QUOTE_SELECTOR));
TypedLiteral startIndex = assertSingleValue(graph, selector, OA_START, TypedLiteral.class);
assertEquals(XSD.int_, startIndex.getDataType());
int start = lf.createObject(Integer.class, startIndex);
TypedLiteral endIndex = assertSingleValue(graph, selector, OA_END, TypedLiteral.class);
assertEquals(XSD.int_, endIndex.getDataType());
int end = lf.createObject(Integer.class, endIndex);
assertTrue(end > start);
//assert the selector URI
assertSelectorUri(contentItem, selector, start, end);
PlainLiteral exact = assertSingleValue(graph, selector, OA_EXACT, PlainLiteral.class);
if(exact != null){
assertEquals(CONTENT_LANGUAGE, exact.getLanguage());
assertEquals(CONTENT.substring(start,end), exact.getLexicalForm());
}
PlainLiteral prefix = assertSingleValue(graph, selector, OA_PREFIX, PlainLiteral.class);
if(prefix != null){
assertEquals(CONTENT_LANGUAGE, prefix.getLanguage());
assertTrue(CONTENT.substring(0,start).endsWith(prefix.getLexicalForm()));
}
PlainLiteral suffix = assertSingleValue(graph, selector, OA_SUFIX, PlainLiteral.class);
if(suffix != null){
assertNotNull("if oa:suffix is present also oa:prefix is expected!",prefix);
assertEquals(CONTENT_LANGUAGE, suffix.getLanguage());
assertTrue(CONTENT.substring(end,CONTENT.length()).startsWith(suffix.getLexicalForm()));
} else {
assertNull("if oa:prefix is present als oa:suffix is expected!",prefix);
}
}
示例12: assertHasValues
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private <T extends Resource> Set<T> assertHasValues(TripleCollection graph,
NonLiteral subject, UriRef property, Class<T> type) {
Iterator<Triple> it = graph.filter(subject, property, null);
assertTrue("missing value for property "+property+ "on subject "+subject, it.hasNext());
Set<T> values = new HashSet<T>();
while(it.hasNext()){
Resource value = it.next().getObject();
assertTrue(type.getSimpleName()+" expected but value "+ value +
" had the type "+value.getClass().getSimpleName()+"!",
type.isAssignableFrom(value.getClass()));
values.add(type.cast(value));
}
return values;
}
示例13: assertHasInvValues
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private <T extends Resource> Set<T> assertHasInvValues(TripleCollection graph, NonLiteral object,
UriRef property, Class<T> type) {
Iterator<Triple> it = graph.filter(null, property, object);
assertTrue("missing incoming value for property "+property+ "on object "+object, it.hasNext());
Set<T> values = new HashSet<T>();
while(it.hasNext()){
Resource value = it.next().getSubject();
assertTrue(type.getSimpleName()+" expected but value "+ value +
" had the type "+value.getClass().getSimpleName()+"!",
type.isAssignableFrom(value.getClass()));
values.add(type.cast(value));
}
return values;
}
示例14: assertSingleValue
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private <T extends Resource> T assertSingleValue(TripleCollection graph, NonLiteral subject, UriRef property, Class<T> type) {
Iterator<Triple> it = graph.filter(subject, property, null);
assertTrue("missing value for property "+property+ "on subject "+subject, it.hasNext());
Resource value = it.next().getObject();
assertFalse("multi values for property "+property+ "on subject "+subject, it.hasNext());
assertTrue(type.getSimpleName()+" expected but was "+value.getClass().getSimpleName()+"!",
type.isAssignableFrom(value.getClass()));
return type.cast(value);
}
示例15: assertOptValue
import org.apache.clerezza.rdf.core.TripleCollection; //导入依赖的package包/类
private <T extends Resource> T assertOptValue(TripleCollection graph, NonLiteral subject, UriRef property, Class<T> type) {
Iterator<Triple> it = graph.filter(subject, property, null);
if(!it.hasNext()){
return null;
}
Resource value = it.next().getObject();
assertFalse("multi values for property "+property+ "on subject "+subject, it.hasNext());
assertTrue(type.getSimpleName()+" expected but was "+value.getClass().getSimpleName()+"!",
type.isAssignableFrom(value.getClass()));
return type.cast(value);
}