本文整理汇总了Java中org.apache.clerezza.rdf.core.Triple类的典型用法代码示例。如果您正苦于以下问题:Java Triple类的具体用法?Java Triple怎么用?Java Triple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Triple类属于org.apache.clerezza.rdf.core包,在下文中一共展示了Triple类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: triplesTest
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
@Test
public void triplesTest() throws IOException, JsonLdError {
final InputStream in = getClass().getClassLoader().getResourceAsStream(
"testfiles/product.jsonld");
final Object input = JsonUtils.fromInputStream(in);
final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();
final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);
for (final Triple t : graph) {
System.out.println(t);
}
assertEquals("Graph size", 13, graph.size());
}
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:17,代码来源:ClerezzaTripleCallbackTest.java
示例2: curiesInContextTest
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
@Test
public void curiesInContextTest() throws IOException, JsonLdError {
final InputStream in = getClass().getClassLoader().getResourceAsStream(
"testfiles/curies-in-context.jsonld");
final Object input = JsonUtils.fromInputStream(in);
final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();
final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);
for (final Triple t : graph) {
System.out.println(t);
assertTrue("Predicate got fully expanded", t.getPredicate().getUnicodeString()
.startsWith("http"));
}
assertEquals("Graph size", 3, graph.size());
}
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:19,代码来源:ClerezzaTripleCallbackTest.java
示例3: serializerTest
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
@Test
public void serializerTest(){
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.serialize(out, rdfData, "application/ld+json");
byte[] data = out.toByteArray();
log.info("Serialized Graph: \n {}",new String(data,UTF8));
//Now we reparse the graph to validate it was serialized correctly
SimpleMGraph reparsed = new SimpleMGraph();
parser.parse(reparsed, new ByteArrayInputStream(data), "application/ld+json");
Assert.assertEquals(7, reparsed.size());
for(Triple t : rdfData){
Assert.assertTrue(reparsed.contains(t));
}
}
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:17,代码来源:ClerezzaJsonLdParserSerializerTest.java
示例4: testTransform
import org.apache.clerezza.rdf.core.Triple; //导入依赖的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();
}
开发者ID:fusepoolP3,项目名称:p3-osm-transformer,代码行数:21,代码来源:OsmXmlParserTest.java
示例5: adaptNotTransformed
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
/**
* Transformed annotation bodies typically do keep the same resource identifier
* as the original <code>fise:Enhancement</code>. So links from not transformed
* resources do keep valid. However in some cases (e.g. where two
* <code>fise:Enhancement</code>s are merged to a single annotation body) this
* will be not the case.<p>
* This methods inspects incoming links of the <code>fise:Enhancement</code>
* in such cases and adapt those to the change resource identifier used by the
* annotation body. Invalid links are removed from the source and the
* corrected one are added to the target graph.
* @param anno the annotation to check
*/
private void adaptNotTransformed(Annotation anno) {
//In case the fise:Enhancement do use a different resource as
//Annotation Body
if(!anno.getBody().equals(anno.enh)){
//we need to redirect links of not transformed resources to the new
//resource
Iterator<Triple> incoming = anno.ctx.ci.getMetadata().filter(null, null, anno.enh);
while(incoming.hasNext()){
Triple t = incoming.next();
if(anno.ctx.getAnnotation(t.getSubject()) == null){ //not transformed
incoming.remove(); //remove the original triple
//add a triple to the new Annotation Body resource to the target grpah
anno.ctx.tar.add(new TripleImpl(t.getSubject(), t.getPredicate(), anno.getBody()));
}
}
}
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:30,代码来源:Fise2FamEngine.java
示例6: cleanFiseEnhancement
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
/**
* Cleans triples in the metadata of the {@link ContentItem} of
* the transformed <code>fise:Enhancement</code>
* @param anno the annotation to clean.
*/
private void cleanFiseEnhancement(Annotation anno) {
MGraph metadata = anno.ctx.ci.getMetadata();
//delete outgoing (incl. bNodes)
List<NonLiteral> nodes = new ArrayList<NonLiteral>();
nodes.add(anno.enh);
while(!nodes.isEmpty()){
Iterator<Triple> outgoing = metadata.filter(
nodes.remove(nodes.size()-1), null, null);
while(outgoing.hasNext()){
Triple t = outgoing.next();
if(t.getObject() instanceof BNode){
nodes.add((BNode)t.getObject());
}
outgoing.remove();
}
}
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:23,代码来源:Fise2FamEngine.java
示例7: transformTextAnnotation
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
private void transformTextAnnotation(Annotation anno) {
//we need to distinquish different types of fise:TextAnnotations
//(1) Language Annotations
Set<UriRef> dcTypes = asSet(getReferences(anno.ctx.src, anno.enh, DC_TYPE));
if (dcTypes.contains(DC_LINGUISTIC_SYSTEM)) { // this is a language annotation
transformLanguageAnnotation(anno);
return;
}
//(2) Sentiment Annotation
//Sentiment Annotations do use ?enh dct:type fise:Sentiment
if(dcTypes.contains(FISE_SENTIMENT_TYPE)){
transformSentimentAnnotation(anno);
return;
}
//(3) Topic Annotations
Iterator<Triple> relation = anno.ctx.src.filter(null, DC_RELATION, anno.enh);
while (relation.hasNext()) {
NonLiteral related = relation.next().getSubject();
if(hasValue(anno.ctx.src, related, RDF_TYPE, null, ENHANCER_TOPICANNOTATION)){
transformTopicClassification(anno);
return;
}
}
//(4) Entity Mention Annotations (all remaining)
transformEntityMentionAnnotation(anno);
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:27,代码来源:Fise2FamEngine.java
示例8: transformTopicAnnotation
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
private void transformTopicAnnotation(Annotation anno) {
Iterator<Triple> relation = anno.ctx.src.filter(anno.enh, DC_RELATION, null);
while(relation.hasNext()){
Resource o = relation.next().getObject();
if(o instanceof NonLiteral){
NonLiteral related = (NonLiteral)o;
if(hasValue(anno.ctx.src, related, RDF_TYPE, null, ENHANCER_TEXTANNOTATION)){
anno.addReated(related); //add this as a related annotation
anno.ctx.tar.add(new TripleImpl(related, OA_ITEM, anno.getBody()));
} //else dc:relation to an none fise:TextAnnotation
} //else dc:relation to an Literal ... ignore
}
if(!anno.getRelated().isEmpty()){
anno.ctx.tar.add(new TripleImpl(anno.getBody(), RDF_TYPE, FAM.TopicAnnotation));
copyValue(anno.ctx, anno.enh, ENHANCER_ENTITY_REFERENCE, anno.getBody(), FAM.topic_reference);
copyValue(anno.ctx, anno.enh, ENHANCER_ENTITY_LABEL, anno.getBody(), FAM.topic_label);
copyValue(anno.ctx, anno.enh, ENTITYHUB_SITE, anno.getBody(), ENTITYHUB_SITE);
}//else ignore Topic Annotations without a Topic Classification
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:21,代码来源:Fise2FamEngine.java
示例9: hasValue
import org.apache.clerezza.rdf.core.Triple; //导入依赖的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;
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:28,代码来源:Fise2FamEngine.java
示例10: assertOptValues
import org.apache.clerezza.rdf.core.Triple; //导入依赖的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;
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:17,代码来源:Fise2FamEngineTest.java
示例11: generateRdf
import org.apache.clerezza.rdf.core.Triple; //导入依赖的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;
}
开发者ID:fusepoolP3,项目名称:p3-pipeline-transformer,代码行数:28,代码来源:SimpleRdfConsumingTransformer.java
示例12: testSilkRdfTurtle
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
@Test
public void testSilkRdfTurtle() throws IOException {
Response response
= RestAssured.given().header("Accept", "text/turtle")
.contentType("text/turtle;charset=UTF-8")
.content(ttlData)
.expect().statusCode(HttpStatus.SC_OK).content(new StringContains("http://www.w3.org/2002/07/owl#sameAs")).header("Content-Type", SupportedFormat.TURTLE).when()
.post();
Graph graph = Parser.getInstance().parse(response.getBody().asInputStream(), "text/turtle");
Iterator<Triple> typeTriples = graph.filter(null, OWL.sameAs, null);
Assert.assertTrue("No equivalent entities found", typeTriples.hasNext());
}
开发者ID:fusepoolP3,项目名称:p3-silkdedup,代码行数:17,代码来源:DuplicatesTransformerTest.java
示例13: testRemoteConfig
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
@Test
public void testRemoteConfig() {
// Set up a service in the mock server to respond to a get request that must be sent by the transformer
// to fetch the silk config file
stubFor(get(urlEqualTo("/fusepoolp3/silk-config-file.xml"))
.willReturn(aResponse()
.withStatus(HttpStatus.SC_OK)
.withHeader("Content-Type", "text/xml")
.withBody(silkconf)));
// The response object acts as a transformer's client. It sends a post request
// to the transformer with the url of the silk config file, the data to be interlinked
// and gets the result from the transformer.
Response response =
RestAssured.given().header("Accept", "text/turtle")
.contentType("text/turtle")
.content(ttlData)
.expect().statusCode(HttpStatus.SC_OK).when()
.post("/?config=http://localhost:" + mockPort +"/fusepoolp3/silk-config-file.xml");
Graph graph = Parser.getInstance().parse(response.getBody().asInputStream(), SupportedFormat.TURTLE);
Iterator<Triple> typeTriples = graph.filter(null, OWL.sameAs, null);
Assert.assertTrue("No equivalent entities found", typeTriples.hasNext());
}
开发者ID:fusepoolP3,项目名称:p3-silkdedup,代码行数:26,代码来源:SilkConfigTest.java
示例14: graphToJson
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
private JSONArray graphToJson(MGraph graph) throws JSONException{
//JSONObject json = new JSONObject();
JSONArray json = new JSONArray();
//create the first 0 element "non assigné"
json.put(getBudgetLineObject("0", "Non assigné", 0));
//TODO : use ldpath for building this ones
//1) get all budget lines
Iterator<Triple> budgetLinesId = graph.filter(null, RDF.type,Onthology.budgetLineType.getUri());
while(budgetLinesId.hasNext()){
Triple budgetId = budgetLinesId.next();
//getthe label
Resource label = graph.filter(budgetId.getSubject(), SKOS.prefLabel, null).next().getObject();
//get the value
Triple valueId = graph.filter(null, Onthology.forBudgetLine.getUri(), budgetId.getSubject()).next();
Resource percentage = graph.filter(valueId.getSubject(), Onthology.percentage.getUri(), null).next().getObject();
json.put(getBudgetLineObject(budgetId.getSubject().toString(), ((Literal)label).getLexicalForm(), Double.parseDouble(((Literal)percentage).getLexicalForm())));
}
return json;
}
开发者ID:florent-andre,项目名称:CleverTaxes,代码行数:27,代码来源:SkosifierRootResource.java
示例15: parse
import org.apache.clerezza.rdf.core.Triple; //导入依赖的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;
}
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:14,代码来源:ClerezzaRDFParser.java
示例16: handleStatement
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
private void handleStatement(RDFDataset result, Triple t, Map<BNode, String> bNodeMap) {
final String subject = getResourceValue(t.getSubject(), bNodeMap);
final String predicate = getResourceValue(t.getPredicate(), bNodeMap);
final Resource object = t.getObject();
if (object instanceof Literal) {
final String value = ((Literal) object).getLexicalForm();
final String language;
final String datatype;
if (object instanceof TypedLiteral) {
language = null;
datatype = getResourceValue(((TypedLiteral) object).getDataType(), bNodeMap);
} else if (object instanceof PlainLiteral) {
// we use RDF 1.1 literals so we do set the RDF_LANG_STRING
// datatype
datatype = RDF_LANG_STRING;
final Language l = ((PlainLiteral) object).getLanguage();
if (l == null) {
language = null;
} else {
language = l.toString();
}
} else {
throw new IllegalStateException("Unknown Literal class "
+ object.getClass().getName());
}
result.addTriple(subject, predicate, value, datatype, language);
count++;
} else {
result.addTriple(subject, predicate, getResourceValue((NonLiteral) object, bNodeMap));
count++;
}
}
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:36,代码来源:ClerezzaRDFParser.java
示例17: getAddress
import org.apache.clerezza.rdf.core.Triple; //导入依赖的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;
}
开发者ID:fusepoolP3,项目名称:p3-osm-transformer,代码行数:33,代码来源:OsmRdfTransformer.java
示例18: testXML
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
@Test
public void testXML() throws Exception {
Transformer t = new TransformerClientImpl(setUpDataServer());
// the transformer fetches the xml data from the data server, geocode the address
// and sends the RDF result to the client
{
Entity response = t.transform(new WritingEntity() {
@Override
public MimeType getType() {
return inputDataMimeType;
}
@Override
public void writeData(OutputStream out) throws IOException {
out.write(inputData);
}
}, transformerMimeType );
// the client receives the response from the transformer
Assert.assertEquals("Wrong media Type of response", TRANSFORMER_MIME_TYPE, response.getType().toString());
// Parse the RDF data returned by the transformer after the geocoding
final Graph responseGraph = Parser.getInstance().parse(response.getData(), "text/turtle");
//checks for the presence of a specific property added by the transformer to the input data
final Iterator<Triple> propertyIter = responseGraph.filter(null, geo_lat, null);
Assert.assertTrue("No specific property found in response", propertyIter.hasNext());
//verify that the xml has been loaded from the data server (one call)
//verify(1,getRequestedFor(urlEqualTo("/xml/" + XML_DATA)));
}
}
开发者ID:fusepoolP3,项目名称:p3-osm-transformer,代码行数:33,代码来源:OsmRdfTransformerTest.java
示例19: transformEntityAnnotation
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
/**
* Implements the transformation rules as specified by
* <a href="https://github.com/fusepoolP3/overall-architecture/blob/master/wp3/fp-anno-model/fp-anno-model.md#fiseentityannotation-transformation">
* <code>fise:EntityAnnotation</code> transformation</a>
* @param source
* @param target
* @param enh
* @return
*/
private void transformEntityAnnotation(Annotation anno) {
//TODO: This does currently not support creating fise:LinkedEntity
// annotations in cases where only a single Entity is suggested
// for a fise:TextAnnotation (fam:EntityMention)
// supporting this would need an additional pass through already
// transformed fise:Enthancements, as one needs to ensure that
// all fise:TextAnnotation are already transformed
Iterator<Triple> mentions = anno.ctx.src.filter(anno.enh, DC_RELATION, null);
while(mentions.hasNext()){
Resource o = mentions.next().getObject();
if(o instanceof NonLiteral){
NonLiteral mention = (NonLiteral)o;
if(hasValue(anno.ctx.src, mention, RDF_TYPE, null, ENHANCER_TEXTANNOTATION)){
anno.addReated(mention); //add this as a related annotation
//adapt EntityMention
anno.ctx.tar.add(new TripleImpl(mention, RDF_TYPE, OA_CHOICE));
anno.ctx.tar.add(new TripleImpl(mention, RDF_TYPE, FAM.EntityLinkingChoice));
anno.ctx.tar.add(new TripleImpl(mention,OA_ITEM, anno.getBody()));
}
} //dc:relation to an Literal ... ignore
}
//add the RDF types to the entity annotation
anno.ctx.tar.add(new TripleImpl(anno.getBody(), RDF_TYPE, FAM.EntityAnnotation));
if(!anno.getRelated().isEmpty()){ //if there is a fam:EntityMention linked
//this is also a fam:EntitySuggestion
anno.ctx.tar.add(new TripleImpl(anno.getBody(), RDF_TYPE, FAM.EntitySuggestion));
}
//direct mappings for fise:EntityAnnotation
copyValue(anno.ctx, anno.enh, ENHANCER_ENTITY_REFERENCE, anno.getBody(), FAM.entity_reference);
copyValue(anno.ctx, anno.enh, ENHANCER_ENTITY_LABEL, anno.getBody(), FAM.entity_label);
copyValue(anno.ctx, anno.enh, ENHANCER_ENTITY_TYPE, anno.getBody(), FAM.entity_type);
copyValue(anno.ctx, anno.enh, ENTITYHUB_SITE, anno.getBody(), ENTITYHUB_SITE);
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:44,代码来源:Fise2FamEngine.java
示例20: copyValue
import org.apache.clerezza.rdf.core.Triple; //导入依赖的package包/类
/**
* Copies values from the source (graph, node, property) to the target (graph,
* node, property).
* @param ctx the {@link TransformationContext}
* @param sourceNode the source node
* @param sourceProp the source property
* @param targetNode the target node
* @param targetProp the target property
* @return the number of values copied
*/
private int copyValue(TransformationContext ctx, NonLiteral sourceNode,
UriRef sourceProp, NonLiteral targetNode,
UriRef targetProp) {
Iterator<Triple> it = ctx.src.filter(sourceNode, sourceProp, null);
int i = 0;
while(it.hasNext()){
Resource val = it.next().getObject();
ctx.tar.add(new TripleImpl(targetNode,targetProp,val));
i++;
}
return i;
}
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:23,代码来源:Fise2FamEngine.java
注:本文中的org.apache.clerezza.rdf.core.Triple类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论