Search in sources :

Example 6 with BlankNodeOrIRI

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

the class EnhancementJob method setCompleted.

/**
     * Sets the state of the parsed executionNode to completed. This also validates if the new state
     * confirms to the ExectionPlan (e.g. if all nodes the parsed node depends on are also marked as
     * completed).
     * 
     * @param execution
     *            the exection to be marked as running
     * @throws IllegalArgumentException
     *             if <code>null</code> is parsed as execution node
     * @throws IllegalStateException
     *             if the parsed execution node can not be marked as completed because some of its
     *             depended nodes are not yet marked as completed.
     */
public void setCompleted(BlankNodeOrIRI execution) {
    if (execution == null) {
        throw new IllegalArgumentException("The parsed em:Execution instance MUST NOT be NULL!");
    }
    writeLock.lock();
    BlankNodeOrIRI executionNode = getExecutionNode(execution);
    log.trace("++ w: {}: {}", "setCompleted", getEngine(executionPlan, executionNode));
    try {
        log.trace(">> w: {}: {}", "setCompleted", getEngine(executionPlan, executionNode));
        setNodeCompleted(executionNode);
        setExecutionCompleted(executionMetadata, execution, null);
    } finally {
        log.trace("<< w: {}: {}", "setCompleted", getEngine(executionPlan, executionNode));
        writeLock.unlock();
    }
}
Also used : BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI)

Example 7 with BlankNodeOrIRI

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

the class EnhancementJob method checkExecutable.

/**
     * updated the {@link #executable} and also checks for {@link #finished}<p>
     * Assumed to be called within a write lock!
     */
private void checkExecutable() {
    Set<BlankNodeOrIRI> executeableNodes = ExecutionPlanHelper.getExecutable(executionPlan, completed);
    //a Chain finishes if no engine is running and no more nodes are executable
    if (!ExecutionMetadata.STATUS_FAILED.equals(getReference(executionMetadata, chainExecutionNode, STATUS))) {
        executeableNodes.removeAll(running);
        if (log.isDebugEnabled()) {
            Collection<String> engines = new ArrayList<String>(executeableNodes.size());
            for (BlankNodeOrIRI node : executeableNodes) {
                engines.add(getEngine(executionPlan, node));
            }
            log.trace("MARK {} as executeable", engines);
        }
        //we need to get the em:Executables for the ep:ExecutionNodes ...
        if (executeableNodes.isEmpty()) {
            this.executable = Collections.emptySet();
        } else if (executeableNodes.size() == 1) {
            this.executable = Collections.singleton(getExecution(executeableNodes.iterator().next()));
        } else {
            Set<BlankNodeOrIRI> executable = new HashSet<BlankNodeOrIRI>(executeableNodes.size());
            for (BlankNodeOrIRI exeutableNode : executeableNodes) {
                executable.add(getExecution(exeutableNode));
            }
            this.executable = Collections.unmodifiableSet(executable);
        }
    } else {
        //do not mark engines as executeable if chain already failed
        this.executable = Collections.emptySet();
    }
    if (isFinished() && !isFailed()) {
        //mark the execution process as completed
        setExecutionCompleted(executionMetadata, chainExecutionNode, null);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) EnhancementEngineHelper.getString(org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString)

Example 8 with BlankNodeOrIRI

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

the class GenericEnhancerUiResource method getExecutionNodes.

/**
     * Getter for the executionNodes
     * 
     * @return
     */
public Set<ExecutionNode> getExecutionNodes() {
    if (_executionNodes == null) {
        ImmutableGraph ep;
        try {
            ep = chain.getExecutionPlan();
        } catch (ChainException e) {
            ep = null;
        }
        if (ep != null) {
            _executionNodes = new LinkedHashSet<ExecutionNode>();
            Set<BlankNodeOrIRI> processed = new HashSet<BlankNodeOrIRI>();
            Set<BlankNodeOrIRI> next;
            do {
                next = ExecutionPlanHelper.getExecutable(ep, processed);
                for (BlankNodeOrIRI node : next) {
                    _executionNodes.add(new ExecutionNode(ep, node));
                }
                processed.addAll(next);
            } while (!next.isEmpty());
        }
    }
    return _executionNodes;
}
Also used : BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) ChainException(org.apache.stanbol.enhancer.servicesapi.ChainException) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with BlankNodeOrIRI

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

the class TikaEngineTest method testMp4.

/**
     * Tests mappings for the Mp4 metadata extraction capabilities added to
     * Tika 1.1 (STANBOL-627)
     * @throws EngineException
     * @throws IOException
     * @throws ParseException
     */
@Test
public void testMp4() throws EngineException, IOException, ParseException {
    log.info(">>> testMp4 <<<");
    ContentItem ci = createContentItem("testMP4.m4a", "audio/mp4");
    assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
    engine.computeEnhancements(ci);
    Entry<IRI, Blob> contentPart = ContentItemHelper.getBlob(ci, singleton("text/plain"));
    assertNotNull(contentPart);
    Blob plainTextBlob = contentPart.getValue();
    assertNotNull(plainTextBlob);
    assertContentRegexp(plainTextBlob, "Test Title", "Test Artist", "Test Album");
    //validate XHTML results
    contentPart = ContentItemHelper.getBlob(ci, singleton("application/xhtml+xml"));
    assertNotNull(contentPart);
    Blob xhtmlBlob = contentPart.getValue();
    assertNotNull(xhtmlBlob);
    //Test AudioTrack metadata
    BlankNodeOrIRI audioTrack = verifyBlankNodeOrIRI(ci, new IRI(NamespaceEnum.media + "hasTrack"));
    //types
    verifyValues(ci, audioTrack, RDF.type, new IRI(NamespaceEnum.media + "MediaFragment"), new IRI(NamespaceEnum.media + "Track"), new IRI(NamespaceEnum.media + "AudioTrack"));
    //properties
    verifyValue(ci, audioTrack, new IRI(NamespaceEnum.media + "hasFormat"), XSD.string, "Stereo");
    verifyValue(ci, audioTrack, new IRI(NamespaceEnum.media + "samplingRate"), XSD.int_, "44100");
    verifyValue(ci, audioTrack, new IRI(NamespaceEnum.media + "hasCompression"), XSD.string, "M4A");
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Blob(org.apache.stanbol.enhancer.servicesapi.Blob) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 10 with BlankNodeOrIRI

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

the class TikaEngineTest method verifyBlankNodeOrIRI.

private static BlankNodeOrIRI verifyBlankNodeOrIRI(ContentItem ci, IRI subject, IRI property) {
    Iterator<Triple> it = ci.getMetadata().filter(subject, property, null);
    assertTrue(it.hasNext());
    RDFTerm r = it.next().getObject();
    assertFalse(it.hasNext());
    assertTrue(r instanceof BlankNodeOrIRI);
    return (BlankNodeOrIRI) r;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm)

Aggregations

BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)89 Triple (org.apache.clerezza.commons.rdf.Triple)52 IRI (org.apache.clerezza.commons.rdf.IRI)41 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)30 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)27 HashSet (java.util.HashSet)24 Graph (org.apache.clerezza.commons.rdf.Graph)22 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)14 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)14 Literal (org.apache.clerezza.commons.rdf.Literal)13 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)12 Lock (java.util.concurrent.locks.Lock)10 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)10 EnhancementEngineHelper.getString (org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString)8 Test (org.junit.Test)8 Collection (java.util.Collection)7 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)7 Language (org.apache.clerezza.commons.rdf.Language)6 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)6