本文整理汇总了Java中org.apache.clerezza.rdf.core.MGraph类的典型用法代码示例。如果您正苦于以下问题:Java MGraph类的具体用法?Java MGraph怎么用?Java MGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MGraph类属于org.apache.clerezza.rdf.core包,在下文中一共展示了MGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: triplesTest
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的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());
}
示例2: curiesInContextTest
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的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());
}
示例3: init
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
@BeforeClass
public static void init(){
LiteralFactory lf = LiteralFactory.getInstance();
UriRef pers1 = new UriRef("http://www.example.org/test#pers1");
UriRef pers2 = new UriRef("http://www.example.org/test#pers2");
MGraph data = new SimpleMGraph();
//NOTE: This test a language literal with and without language as
// well as a xsd:string typed literal. To test correct handling of
// RDF1.1
data.add(new TripleImpl(pers1, RDF.type, FOAF.Person));
data.add(new TripleImpl(pers1, FOAF.name, new PlainLiteralImpl("Rupert Westenthaler",
new Language("de"))));
data.add(new TripleImpl(pers1, FOAF.nick, new PlainLiteralImpl("westei")));
data.add(new TripleImpl(pers1, FOAF.mbox, lf.createTypedLiteral("[email protected]")));
data.add(new TripleImpl(pers1, FOAF.age, lf.createTypedLiteral(38)));
data.add(new TripleImpl(pers1, FOAF.knows, pers2));
data.add(new TripleImpl(pers2, FOAF.name, new PlainLiteralImpl("Reto Bachmann-Gmür")));
rdfData = data.getGraph();
}
示例4: cleanFiseEnhancement
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的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();
}
}
}
示例5: graphToJson
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的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;
}
示例6: createBudgetLine
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
/**
* Return the budget line Object id and populate trpList with created triples
* @param trpList
* @param name
* @param childrens
* @return
*/
private UriRef createBudgetLine(MGraph trpList,String name, List<String> childrens){
UriRef budgetLineRoot = Entities.generateNewEntity();
//creation du nom
//TODO : real language aware object creation
trpList.add(new TripleImpl(budgetLineRoot, SKOS.prefLabel, lf.createTypedLiteral(name)));
//add type of object
trpList.add(new TripleImpl(budgetLineRoot, RDF.type, Onthology.budgetLineType.getUri()));
//create childrens for each parent
for(String child : childrens){
UriRef childBudgetLine = createBudgetLine(trpList, child, Collections.<String> emptyList());
trpList.add(new TripleImpl(budgetLineRoot, Onthology.hasBudgetLine.getUri(), childBudgetLine));
}
return budgetLineRoot;
}
示例7: getSkosOnto
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
@Deprecated //"use the model endpoint instead
@Path("/skosontology/all")
@GET
@Consumes(WILDCARD)
@Produces(RDF_XML)
//TODO : change query parameter name from skos to \"model"
//TODO : change endpoint from skosontology to ontologiesmodel
//TODO : remove the \"/all" and remove the /skosontology model
//TODO : without model parameter, this endpoint provide the list of available ontologies
//TODO : remove the skos_ prefix in the file name as it not really mean something
public Response getSkosOnto(@QueryParam(value = "skos") String modelName, @Context HttpHeaders headers) throws JSONException {
log.warn("This endpoint is deprecated, use the model endpoint instead");
UriRef soURI = new UriRef("urn:x-onto-utils:skosOntology" + modelName);
MGraph g;
Set<UriRef> l = tcManager.listMGraphs();
if(l.contains(soURI)){
g = tcManager.getMGraph(soURI);
}
else{
//initialisation, loading of the graph
g = tcManager.createMGraph(soURI);
g.addAll(parser.parse(this.getClass().getResourceAsStream("/skos_"+modelName+".rdf"), "Application/rdf+xml"));
}
return okMGraphResponse(headers, g);
}
示例8: writeEntityInformation
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
private void writeEntityInformation(MGraph writer, Keyword keyword, UriRef entity, Language lang) {
//The rdfs:label
writer.add(new TripleImpl(entity, RDFS_LABEL,
new PlainLiteralImpl(keyword.getForm(), lang)));
//the rdf:type
for(Clazz type : keyword.getClasses()){
writer.add(new TripleImpl(entity, RDF_TYPE, new UriRef(type.getUrl().toString())));
UriRef dbpediaType = createDbpediaTypeUri(type);
if(dbpediaType != null){
writer.add(new TripleImpl(entity, RDF_TYPE, dbpediaType));
}
}
if(keyword.getAbstract() != null){
writer.add(new TripleImpl(entity, RDFS_COMMENT,
new PlainLiteralImpl(keyword.getAbstract(),lang)));
}
if(keyword.getImages() != null && keyword.getImages().length > 0){
Image image = keyword.getImages()[0];
// for(Image image : keyword.getImages()){
writer.add(new TripleImpl(entity, FOAF_DEPICTION, new UriRef(image.getImage().toString())));
writer.add(new TripleImpl(entity, FOAF_THUMBNAIL, new UriRef(image.getThumb().toString())));
// }
}
}
开发者ID:michelemostarda,项目名称:machinelinking-stanbol-enhancement-engine,代码行数:25,代码来源:MLAnnotateEnhancementEngine.java
示例9: uploadRdf
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
/**
* Load RDF data sent by HTTP POST. Use the Dataset custom header
* to address the dataset in which to store the rdf data.
* Use this service with the following curl command:
* curl -X POST -u admin: -H "Content-Type: application/rdf+xml"
* -H "Dataset: mydataset" -T <rdf_file> http://localhost:8080/dlcupload/rdf
*/
@POST
@Path("rdf")
@Produces("text/plain")
public String uploadRdf(@Context final UriInfo uriInfo,
@HeaderParam("Content-Type") String mediaType,
@HeaderParam("Dataset") String dataset,
final InputStream stream) throws Exception {
AccessController.checkPermission(new AllPermission());
final MGraph graph = new SimpleMGraph();
String message = "";
if(mediaType.equals(SupportedFormat.RDF_XML)) {
parser.parse(graph, stream, SupportedFormat.RDF_XML);
}
else {
message = "Add header Content-Type: application/rdf+xml ";
}
return message + "Added " + graph.size() + " triples to dataset " + dataset + "\n";
}
示例10: addTriples
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
/**
* Load RDF data into an existing graph from a URL (schemes: "file://" or
* "http://"). The arguments to be passed are: 1) graph in which the RDF
* data must be stored 2) url of the dataset After the upload the input
* graph is sent to a digester to extract text for indexing and adding
* entities found by NLP components (in the default chain) as subject
*
* @return the added triples
*/
private MGraph addTriples(DataSet dataSet, URL dataUrl, PrintWriter messageWriter) throws IOException {
AccessController.checkPermission(new AllPermission());
// add the triples of the temporary graph into the graph selected by the user
if (isValidUrl(dataUrl)) {
MGraph updatedGraph = addTriplesCommand(dataSet.getSourceGraph(), dataUrl);
messageWriter.println("Added " + updatedGraph.size() + " triples from " + dataUrl + " to " + dataSet.getSourceGraphRef().getUnicodeString());
return updatedGraph;
} else {
messageWriter.println("The URL of the data is not a valid one.");
throw new RuntimeException("Invalid URL; " + dataUrl);
}
}
示例11: addTriplesCommand
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
/**
*
* Add triples to graph
*/
private MGraph addTriplesCommand(LockableMGraph targetGraph, URL dataUrl) throws IOException {
AccessController.checkPermission(new AllPermission());
URLConnection connection = dataUrl.openConnection();
connection.addRequestProperty("Accept", "application/rdf+xml; q=.9, text/turte;q=1");
// create a temporary graph to store the data
SimpleMGraph tempGraph = new SimpleMGraph();
String mediaType = connection.getHeaderField("Content-type");
if ((mediaType == null) || mediaType.equals("application/octet-stream")) {
mediaType = guessContentTypeFromUri(dataUrl);
}
InputStream data = connection.getInputStream();
if (data != null) {
parser.parse(tempGraph, data, mediaType);
targetGraph.addAll(tempGraph);
}
return tempGraph;
}
示例12: extractTextFromRdf
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
/**
* Extract text from dcterms:title and dcterms:abstract fields in the source
* graph and adds a sioc:content property with that text in the enhance
* graph. The text is used by the ECS for indexing. The keywords will be
* related to the resource so that it could be retrieved.
*
* @return
*/
private void extractTextFromRdf(DataSet dataSet, String selectedDigester, PrintWriter messageWriter) {
RdfDigester digester = digesters.get(selectedDigester);
MGraph tempGraph = new IndexedMGraph();
LockableMGraph sourceGraph = dataSet.getSourceGraph();
Lock rl = sourceGraph.getLock().readLock();
rl.lock();
try {
tempGraph.addAll(sourceGraph);
} finally {
rl.unlock();
}
digester.extractText(tempGraph);
tempGraph.removeAll(sourceGraph);
dataSet.getDigestGraph().addAll(tempGraph);
messageWriter.println("Extracted text from " + dataSet.getDigestGraphRef().getUnicodeString() + " by " + selectedDigester + " digester");
}
示例13: TransformationContext
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
TransformationContext(ContentItem ci, MGraph target){
if(ci == null){
throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL!");
}
this.ci = ci;
this.src = ci.getMetadata();
this.tar = target == null ? new SimpleMGraph() : target;
}
示例14: read
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
public Map<String,Collection<Object>> read(Exchange exchange) throws IOException, LDPathParseException, InvalidPayloadException {
final String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
final String subject = exchange.getIn().getHeader(LDPATH_CONTEXT, String.class);
final ParsingProvider parser = new JenaParserProvider();
final MGraph graph = new SimpleMGraph();
if (isBlank(contentType)) {
throw new IOException("Empty or missing Content-Type header identifying the RDF format");
}
if (isBlank(subject)) {
throw new IOException("Empty or missing LDPATH_CONTEXT header, identifying the context for the LDPath program");
}
parser.parse(graph, getBodyAsInputStream(exchange),
"application/n-triples".equals(contentType) ? "text/rdf+nt" : contentType, null);
final UriRef context = new UriRef(subject);
final ClerezzaBackend backend = new ClerezzaBackend(graph);
final LDPath<Resource> ldpath = new LDPath<Resource>(backend);
final Map<String, Collection<?>> results = ldpath.programQuery(context, query);
final Map<String, Collection<Object>> transformed = transformLdpathOutput(results);
Map<String, Collection<Object>> ldTransform = new HashMap<>();
for (Map.Entry<String, Collection<Object>> entry : transformed.entrySet()) {
if (entry.getValue().size() > 0) {
ldTransform.put(entry.getKey(), entry.getValue());
}
}
if (ldTransform.size() > 0) {
return ldTransform;
} else {
return null;
}
}
示例15: getGraph
import org.apache.clerezza.rdf.core.MGraph; //导入依赖的package包/类
@GET
@Consumes(WILDCARD)
public Response getGraph(@QueryParam(value = "name") String name,
@Context HttpHeaders headers) throws JSONException{
MGraph graph;
try{
graph = tcManager.getMGraph(uriBuilder(name));
}catch(NoSuchEntityException e){
log.warn("implementation new graph création");
graph = tcManager.createMGraph(uriBuilder(name));
}
JSONObject jo = new JSONObject();
if(name.equals("demo")){
graph.clear();
generateDemoData(graph,Entities.generateNewEntity(name.concat("-")));
}
log.warn("TODO :: create the object from data if any contained");
//ResponseBuilder rb = Response.ok(jo.toString());
//ResponseBuilder rb = Response.ok(graph);
ResponseBuilder rb = Response.ok(graphToJson(graph).toString());
enableCORS(servletContext,rb, headers);
return rb.build();
}