Search in sources :

Example 26 with TripleImpl

use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.

the class EnhancementEngineHelper method getChainExecutionProperties.

/**
 * Getter for the {@link Chain} scoped (chain and chain-engine scoped) properties
 * for the parsed enhancement engine and content item.
 * @param engine the enhancement engine
 * @param ci the content item
 * @return the chain scoped enhancement properties. This will not include any
 * request scoped properties.
 * @since 0.12.1 (<a href="https://issues.apache.org/jira/browse/STANBOL-1361">STANBOL-1361</a>)
 */
public static Map<String, Object> getChainExecutionProperties(EnhancementEngine engine, ContentItem ci) {
    if (engine == null) {
        throw new IllegalArgumentException("The parsed EnhancementEngine MUST NOT be NULL");
    }
    if (ci == null) {
        throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL");
    }
    Map<String, Object> chainExProps = new HashMap<String, Object>();
    Map<String, Object> engineExProps = new HashMap<String, Object>();
    ci.getLock().readLock().lock();
    try {
        Graph em = ExecutionMetadataHelper.getExecutionMetadata(ci);
        // (1.a) retrieve EnhancementProperties from the ep:ExecutionPlan
        log.debug("> extract EnhancementProperties form the ExecutionPlan");
        BlankNodeOrIRI executionPlanNode = ExecutionMetadataHelper.getExecutionPlanNode(em, ExecutionMetadataHelper.getChainExecution(em, ci.getUri()));
        extractEnhancementProperties(chainExProps, em, executionPlanNode, "Chain Execution");
        // (1.b) retrieve Enhancement Properties from the ep:ExectutionNode
        // for the parsed EnhancementEngine
        log.debug("> extract EnhancementProperties form the ExecutionNode of Engine {}", engine.getName());
        Iterator<Triple> engineExecutions = em.filter(null, ExecutionPlan.ENGINE, new PlainLiteralImpl(engine.getName()));
        // there are multiple we will merge the properties of those
        while (engineExecutions.hasNext()) {
            BlankNodeOrIRI engineExecution = engineExecutions.next().getSubject();
            if (em.contains(new TripleImpl(executionPlanNode, ExecutionPlan.HAS_EXECUTION_NODE, engineExecution))) {
                extractEnhancementProperties(engineExProps, em, engineExecution, "Engine Execution");
            }
        // else engine execution of a different execution plan
        }
    } catch (NoSuchPartException e) {
        // no execution metadata are present
        log.debug("  - no ExecutionMetadata are present ...");
    } finally {
        ci.getLock().readLock().unlock();
    }
    // finally merge the chain-engine scoped properties into the chain scoped properties
    chainExProps.putAll(engineExProps);
    return chainExProps;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) Graph(org.apache.clerezza.commons.rdf.Graph) HashMap(java.util.HashMap) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) NoSuchPartException(org.apache.stanbol.enhancer.servicesapi.NoSuchPartException) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 27 with TripleImpl

use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.

the class EnhancementEngineHelper method createTextEnhancement.

/**
 * Create a new instance with the types enhancer:Enhancement and
 * enhancer:TextAnnotation in the parsed graph along with default properties
 * (dc:creator, dc:created and enhancer:extracted-form) and return
 * the IRI of the extraction so that engines can further add.
 *
 * @param metadata the graph
 * @param engine the engine
 * @param contentItemId the id
 *
 * @return the URI of the new enhancement instance
 */
public static IRI createTextEnhancement(Graph metadata, EnhancementEngine engine, IRI contentItemId) {
    IRI enhancement = createEnhancement(metadata, engine, contentItemId);
    // add the Text Annotation Type
    metadata.add(new TripleImpl(enhancement, RDF_TYPE, ENHANCER_TEXTANNOTATION));
    return enhancement;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 28 with TripleImpl

use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.

the class ExecutionPlanHelper method createExecutionPlan.

/**
 * Creates an ExecutionPlan for the parsed chainName in the parsed ImmutableGraph
 * @param graph the graph
 * @param chainName the chain name
 * @param enhProps the map with the enhancement properties defined for the
 * chain or <code>null</code> if none
 * @return the node representing the ex:ExecutionPlan
 * @since 0.12.1
 */
public static BlankNodeOrIRI createExecutionPlan(Graph graph, String chainName, Map<String, Object> enhProps) {
    if (graph == null) {
        throw new IllegalArgumentException("The parsed Graph MUST NOT be NULL!");
    }
    if (chainName == null || chainName.isEmpty()) {
        throw new IllegalArgumentException("The parsed Chain name MUST NOT be NULL nor empty!");
    }
    BlankNodeOrIRI node = new BlankNode();
    graph.add(new TripleImpl(node, RDF_TYPE, EXECUTION_PLAN));
    graph.add(new TripleImpl(node, CHAIN, new PlainLiteralImpl(chainName)));
    writeEnhancementProperties(graph, node, null, enhProps);
    return node;
}
Also used : PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 29 with TripleImpl

use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.

the class ExecutionMetadataHelper method setExecutionSkipped.

/**
 * Sets an execution node to skipped. This sets both the start and the completed
 * time to the current time.
 * @param graph
 * @param execution
 * @param message An optional message why this execution was skipped
 */
public static void setExecutionSkipped(Graph graph, BlankNodeOrIRI execution, String message) {
    Literal dateTime = lf.createTypedLiteral(new Date());
    setStatus(graph, execution, STATUS_SKIPPED);
    graph.add(new TripleImpl(execution, STARTED, dateTime));
    graph.add(new TripleImpl(execution, COMPLETED, dateTime));
    if (message != null) {
        graph.add(new TripleImpl(execution, STATUS_MESSAGE, new PlainLiteralImpl(message)));
    }
}
Also used : PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) Literal(org.apache.clerezza.commons.rdf.Literal) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Date(java.util.Date)

Example 30 with TripleImpl

use of org.apache.clerezza.commons.rdf.impl.utils.TripleImpl in project stanbol by apache.

the class GraphMultiplexer method updateSessionRegistration.

private void updateSessionRegistration(Session session) {
    final IRI sesur = getIRIforSession(session);
    // If this method was called after a session rebuild, the following will have little to no effect.
    synchronized (meta) {
        // The only essential triple to add is typing
        meta.add(new TripleImpl(sesur, RDF.type, SESSION_URIREF));
    }
    log.debug("Ontology collector information triples added for session \"{}\".", sesur);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Aggregations

TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)143 IRI (org.apache.clerezza.commons.rdf.IRI)104 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)69 Graph (org.apache.clerezza.commons.rdf.Graph)66 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)49 Triple (org.apache.clerezza.commons.rdf.Triple)41 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)26 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)23 HashMap (java.util.HashMap)20 Language (org.apache.clerezza.commons.rdf.Language)20 Literal (org.apache.clerezza.commons.rdf.Literal)20 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)20 IOException (java.io.IOException)18 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)17 Test (org.junit.Test)16 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)15 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)14 HashSet (java.util.HashSet)13 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)13 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)11