use of org.apache.clerezza.rdf.core.serializedform.Parser in project stanbol by apache.
the class ContentItemReaderWriterTest method createTestContentItem.
/**
* @return
*/
@BeforeClass
public static void createTestContentItem() throws IOException {
contentItem = ciFactory.createContentItem(new IRI("urn:test"), new StringSource("<html>\n" + " <body>\n" + " This is a <b>ContentItem</b> to <i>Mime Multipart</i> test!\n" + " </body>\n" + "</html>", "text/html"));
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
contentItem.addPart(new IRI("run:text:text"), ciFactory.createBlob(new StringSource("This is a ContentItem to Mime Multipart test!")));
contentItem.getMetadata().add(new TripleImpl(new IRI("urn:test"), RDF.type, new IRI("urn:types:Document")));
//mark the main content as parsed and also that all
//contents and contentparts should be included
Map<String, Object> properties = initRequestPropertiesContentPart(contentItem);
properties.put(PARSED_CONTENT_URIS, Collections.singleton(contentItem.getPartUri(0).getUnicodeString()));
properties.put(OUTPUT_CONTENT, Collections.singleton("*/*"));
properties.put(OUTPUT_CONTENT_PART, Collections.singleton("*"));
properties.put(RDF_FORMAT, "application/rdf+xml");
Graph em = initExecutionMetadataContentPart(contentItem);
BlankNodeOrIRI ep = createExecutionPlan(em, "testChain", null);
writeExecutionNode(em, ep, "testEngine", true, null, null);
initExecutionMetadata(em, em, contentItem.getUri(), "testChain", false);
ciWriter = new ContentItemWriter(Serializer.getInstance());
ciReader = new ContentItemReader() {
@Override
protected Parser getParser() {
return Parser.getInstance();
}
@Override
protected ContentItemFactory getContentItemFactory() {
return ciFactory;
}
};
}
use of org.apache.clerezza.rdf.core.serializedform.Parser in project stanbol by apache.
the class TopicEngineTest method testImportModelFromSKOS.
@Test
public void testImportModelFromSKOS() throws Exception {
log.info(" --- testImportModelFromSKOS --- ");
Parser parser = Parser.getInstance();
parser.bindParsingProvider(new JenaParserProvider());
ImmutableGraph graph = parser.parse(getClass().getResourceAsStream("/sample-scheme.skos.rdf.xml"), SupportedFormat.RDF_XML);
int imported = classifier.importConceptsFromGraph(graph, OntologicalClasses.SKOS_CONCEPT, Properties.SKOS_BROADER);
assertEquals(imported, 4);
assertEquals(0, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/100").size());
assertEquals(0, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/200").size());
assertEquals(1, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/010").size());
assertEquals(1, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/020").size());
assertEquals(2, classifier.getRootConcepts().size());
}
use of org.apache.clerezza.rdf.core.serializedform.Parser in project stanbol by apache.
the class OpenCalaisEngine method readModel.
/**
* Parses an InputStream of RDF data and produces an Graph from them
*
* @param in The InputStream of RDF data
* @param format the format of the RDF data
*
* @return the resulting Graph or null if the RDF serialization format is not supported by the parser
*/
public Graph readModel(InputStream in, String format) {
Parser parser = Parser.getInstance();
if (parser.getSupportedFormats().contains(format)) {
ImmutableGraph graph = parser.parse(in, format);
Graph model = new SimpleGraph(graph);
return model;
} else {
log.warn("Unsupported RDF format: {}\nSupported RDF formats: {}", format, parser.getSupportedFormats());
}
return null;
}
use of org.apache.clerezza.rdf.core.serializedform.Parser in project stanbol by apache.
the class XsltExtractor method extract.
public synchronized void extract(String id, Document doc, Map<String, Object> params, Graph result) throws ExtractorException {
if (params == null) {
params = new HashMap<String, Object>();
}
params.put(this.uriParameter, id);
initTransformerParameters(params);
Source source = new DOMSource(doc);
ByteArrayOutputStream writer = new ByteArrayOutputStream(8192);
StreamResult output = new StreamResult(writer);
try {
this.transformer.transform(source, output);
if (LOG.isDebugEnabled()) {
String rdf = writer.toString("UTF-8");
LOG.debug(rdf);
}
InputStream reader = new ByteArrayInputStream(writer.toByteArray());
Parser rdfParser = Parser.getInstance();
ImmutableGraph graph = rdfParser.parse(reader, this.syntax);
result.addAll(graph);
} catch (TransformerException e) {
throw new ExtractorException(e.getMessage(), e);
} catch (IOException e) {
throw new ExtractorException(e.getMessage(), e);
}
}
Aggregations