use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class ContentItemFactoryTest method testDefaultId.
/**
* Test the generation of valid IDs if no or <code>null</code> is parsed
* as id
*/
@Test
public void testDefaultId() throws IOException {
ContentItem ci = contentItemFactory.createContentItem(TEST_CS);
assertNotNull(ci);
assertNotNull(ci.getUri());
ci = contentItemFactory.createContentItem((IRI) null, TEST_CS);
assertNotNull(ci);
assertNotNull(ci.getUri());
ci = contentItemFactory.createContentItem((IRI) null, TEST_CS, new SimpleGraph());
assertNotNull(ci);
assertNotNull(ci.getUri());
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class AbstractOntologyCollectorImpl method getMergedTc.
private Graph getMergedTc() {
// Takes less memory than the Indexed one
Graph result = new SimpleGraph();
for (OWLOntologyID key : listManagedOntologies()) {
// TODO when implemented, switch to true.
Graph managed = getOntology(key, Graph.class, false);
Set<RDFTerm> exclusions = new HashSet<RDFTerm>();
Iterator<Triple> it = managed.filter(null, RDF.type, OWL.Ontology);
while (it.hasNext()) exclusions.add(it.next().getSubject());
for (Triple t : managed) if (!exclusions.contains(t.getSubject()))
result.add(t);
}
return result;
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class JenaToClerezzaConverter method jenaModelToClerezzaGraph.
/**
*
* Converts a Jena {@link Model} to Clerezza {@link Graph}.
*
* @param model {@link Model}
* @return the equivalent Clerezza {@link Graph}.
*/
public static org.apache.clerezza.commons.rdf.Graph jenaModelToClerezzaGraph(Model model) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
model.write(out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ParsingProvider parser = new JenaParserProvider();
org.apache.clerezza.commons.rdf.Graph mGraph = new SimpleGraph();
parser.parse(mGraph, in, SupportedFormat.RDF_XML, null);
return mGraph;
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class IndexedGraphTest method testPerformance.
@Test
public void testPerformance() {
//Reduced values to fix STANBOL-
Set<Triple> graph = new HashSet<Triple>();
//reduced from 1000
int iterations = 100;
int graphsize = 100000;
Long seed = System.currentTimeMillis();
log.info("Test Seed: {}", seed);
createGraph(graph, graphsize, seed);
log.info("Load Time ({} triples)", graph.size());
long start = System.currentTimeMillis();
Graph sg = new SimpleGraph(graph);
log.info(" ... {}: {}", sg.getClass().getSimpleName(), System.currentTimeMillis() - start);
start = System.currentTimeMillis();
Graph ig = new IndexedGraph(graph);
log.info(" ... {}: {}", ig.getClass().getSimpleName(), System.currentTimeMillis() - start);
//Simple ImmutableGraph reference test
//reduced form 100,5,100
TestCase testCase = new TestCase(sg, 20, 5, 20);
log.info("Filter Performance Test (graph size {} triples, iterations {})", graphsize, iterations);
log.info(" --- TEST {} with {} triples ---", sg.getClass().getSimpleName(), sg.size());
start = System.currentTimeMillis();
List<Long> sgr = executeTest(sg, testCase, iterations);
log.info(" --- TEST completed in {}ms", System.currentTimeMillis() - start);
log.info(" --- TEST {} {} triples ---", ig.getClass().getSimpleName(), sg.size());
start = System.currentTimeMillis();
List<Long> igr = executeTest(ig, testCase, iterations);
log.info(" --- TEST completed in {}ms", System.currentTimeMillis() - start);
//validate filter implementation
Assert.assertEquals(sgr, igr);
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class TestHtmlExtractor method testRdfaExtraction.
/**
* This tests the RDFa extraction.
*
* @throws ExtractorException if there is an error during extraction
* @throws IOException if there is an error when reading the document
*/
@Test
public void testRdfaExtraction() throws Exception {
HtmlExtractor extractor = new HtmlExtractor(registry, parser);
Graph model = new SimpleGraph();
String testFile = "test-rdfa.html";
// extract text from RDFa annotated html
InputStream in = getResourceAsStream(testFile);
assertNotNull("failed to load resource " + testFile, in);
extractor.extract("file://" + testFile, in, null, "text/html", model);
// show triples
int tripleCounter = model.size();
LOG.debug("RDFa triples: {}", tripleCounter);
printTriples(model);
assertEquals(8, tripleCounter);
ClerezzaRDFUtils.makeConnected(model, new IRI("file://" + testFile), new IRI(NIE_NS + "contains"));
}
Aggregations