Search in sources :

Example 36 with Graph

use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.

the class IndexedGraphTest method remove.

@Test(expected = ConcurrentModificationException.class)
public void remove() {
    Graph itc = new IndexedGraph();
    itc.add(triple1);
    itc.add(triple2);
    itc.add(triple3);
    itc.add(triple4);
    itc.add(triple5);
    Iterator<Triple> iter = itc.filter(uriRef1, null, null);
    while (iter.hasNext()) {
        Triple triple = iter.next();
        itc.remove(triple);
    }
    Assert.assertEquals(3, itc.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 37 with Graph

use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.

the class IndexedGraphTest method filterIteratorRemove.

@Test
public void filterIteratorRemove() {
    Graph itc = new IndexedGraph();
    itc.add(triple1);
    itc.add(triple2);
    itc.add(triple3);
    itc.add(triple4);
    itc.add(triple5);
    Iterator<Triple> iter = itc.filter(uriRef1, null, null);
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    Assert.assertEquals(3, itc.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 38 with Graph

use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.

the class IndexedGraphTest method iteratorRemove.

@Test
public void iteratorRemove() {
    Graph itc = new IndexedGraph();
    itc.add(triple1);
    itc.add(triple2);
    itc.add(triple3);
    itc.add(triple4);
    itc.add(triple5);
    Iterator<Triple> iter = itc.iterator();
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    Assert.assertEquals(0, itc.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 39 with Graph

use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.

the class IndexedGraphTest method bNodeConsitency.

@Test
public void bNodeConsitency() {
    Graph mGraph = getEmptyGraph();
    final BlankNode bNode = new BlankNode() {

        @Override
        public int hashCode() {
            return -1;
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof BlankNode;
        }
    };
    final BlankNode bNodeClone = new BlankNode() {

        @Override
        public int hashCode() {
            return -1;
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof BlankNode;
        }
    };
    mGraph.add(new TripleImpl(bNode, uriRef1, uriRef2));
    mGraph.add(new TripleImpl(bNodeClone, uriRef2, uriRef3));
    BlankNodeOrIRI bNodeBack = mGraph.filter(null, uriRef1, uriRef2).next().getSubject();
    Assert.assertEquals("The bnode we get back is not equals to the one we added", bNode, bNodeBack);
    BlankNodeOrIRI bNodeBack2 = mGraph.filter(null, uriRef2, uriRef3).next().getSubject();
    Assert.assertEquals("The returnned bnodes are no longer equals", bNodeBack, bNodeBack2);
    Assert.assertTrue("Not finding a triple when searching with equal bNode", mGraph.filter(bNodeBack, uriRef2, null).hasNext());
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 40 with Graph

use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.

the class ListChain method activate.

@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
    super.activate(ctx);
    Object value = ctx.getProperties().get(PROPERTY_ENGINE_LIST);
    List<String> configuredChain = new ArrayList<String>();
    if (value instanceof String[]) {
        configuredChain.addAll(Arrays.asList((String[]) value));
    } else if (value instanceof List<?>) {
        for (Object o : (List<?>) value) {
            if (o != null) {
                configuredChain.add(o.toString());
            }
        }
    } else {
        throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The engines of a List Chain MUST BE configured as Array/List of " + "Strings (parsed: " + (value != null ? value.getClass() : "null") + ")");
    }
    Set<String> engineNames = new HashSet<String>(configuredChain.size());
    BlankNodeOrIRI last = null;
    Graph ep = new SimpleGraph();
    BlankNodeOrIRI epNode = createExecutionPlan(ep, getName(), getChainProperties());
    log.debug("Parse ListChain config:");
    for (String line : configuredChain) {
        try {
            Entry<String, Map<String, List<String>>> parsed = ConfigUtils.parseConfigEntry(line);
            if (!engineNames.add(parsed.getKey())) {
                throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The EnhancementEngine '" + parsed.getKey() + "' is mentioned" + "twice in the configured list!");
            }
            boolean optional = getState(parsed.getValue(), "optional");
            log.debug(" > Engine: {} ({})", parsed.getKey(), optional ? "optional" : "required");
            last = writeExecutionNode(ep, epNode, parsed.getKey(), optional, last == null ? null : Collections.singleton(last), getEnhancementProperties(parsed.getValue()));
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(PROPERTY_ENGINE_LIST, "Unable to parse Chain Configuraiton (message: '" + e.getMessage() + "')!", e);
        }
    }
    if (engineNames.isEmpty()) {
        throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The configured chain MUST at least contain a single valid entry!");
    }
    this.engineNames = Collections.unmodifiableSet(engineNames);
    this.executionPlan = ep.getImmutableGraph();
}
Also used : ArrayList(java.util.ArrayList) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) ConfigurationException(org.osgi.service.cm.ConfigurationException) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Graph (org.apache.clerezza.commons.rdf.Graph)172 IRI (org.apache.clerezza.commons.rdf.IRI)110 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)66 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)57 Triple (org.apache.clerezza.commons.rdf.Triple)45 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)43 Test (org.junit.Test)38 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)36 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)34 IOException (java.io.IOException)27 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)26 HashSet (java.util.HashSet)24 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)24 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)24 InputStream (java.io.InputStream)21 HashMap (java.util.HashMap)20 Language (org.apache.clerezza.commons.rdf.Language)17 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)17 ArrayList (java.util.ArrayList)16 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)15