Search in sources :

Example 1 with ResourceImpl

use of org.apache.jena.rdf.model.impl.ResourceImpl in project jena by apache.

the class TestFmtUtils method stringForRDFNode_resource.

@Test
public void stringForRDFNode_resource() {
    final ResourceImpl rdfNod = new ResourceImpl(aUriRemappableNode(), null);
    assertEquals("zz:abs", stringForRDFNode(rdfNod, getContext()));
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) Test(org.junit.Test)

Example 2 with ResourceImpl

use of org.apache.jena.rdf.model.impl.ResourceImpl in project jena by apache.

the class BaseXMLWriter method setBlockRules.

Resource[] setBlockRules(Object o) {
    Resource[] rslt = blockedRules;
    unblockAll();
    if (o instanceof Resource[]) {
        blockedRules = (Resource[]) o;
    } else {
        StringTokenizer tkn = new StringTokenizer((String) o, ", ");
        Vector<Resource> v = new Vector<>();
        while (tkn.hasMoreElements()) {
            String frag = tkn.nextToken();
            //  System.err.println("Blocking " + frag);
            v.add(new ResourceImpl(RDFSyntax.getURI() + frag));
        }
        blockedRules = new Resource[v.size()];
        v.copyInto(blockedRules);
    }
    for (Resource blockedRule : blockedRules) {
        blockRule(blockedRule);
    }
    return rslt;
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl)

Example 3 with ResourceImpl

use of org.apache.jena.rdf.model.impl.ResourceImpl in project webofneeds by researchstudio-sat.

the class BATestScriptListener method assertCorrectConnectionState.

private void assertCorrectConnectionState(final URI fromCon, final BATestScriptAction action) {
    LinkedDataSource linkedDataSource = getEventListenerContext().getLinkedDataSource();
    if (linkedDataSource instanceof CachingLinkedDataSource) {
        ((CachingLinkedDataSource) linkedDataSource).invalidate(fromCon);
    }
    logger.debug("fromCon {}, stateOfSenderBeforeSending{}", fromCon, action.getStateOfSenderBeforeSending());
    Dataset dataModel = linkedDataSource.getDataForResource(fromCon);
    logger.debug("crawled dataset for fromCon {}: {}", fromCon, RdfUtils.toString(dataModel));
    String sparqlPrefix = "PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>" + "PREFIX geo:   <http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>" + "PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX won:   <http://purl.org/webofneeds/model#>" + "PREFIX wontx:   <http://purl.org/webofneeds/tx/model#>" + "PREFIX gr:    <http://purl.org/goodrelations/v1#>" + "PREFIX sioc:  <http://rdfs.org/sioc/ns#>" + "PREFIX ldp:   <http://www.w3.org/ns/ldp#>";
    String queryString = sparqlPrefix + "ASK WHERE { ?con wontx:hasBAState ?state }";
    QuerySolutionMap binding = new QuerySolutionMap();
    binding.add("con", new ResourceImpl(fromCon.toString()));
    binding.add("state", new ResourceImpl(action.getStateOfSenderBeforeSending().toString()));
    Query query = QueryFactory.create(queryString);
    QueryExecution qExec = QueryExecutionFactory.create(query, dataModel, binding);
    boolean result = qExec.execAsk();
    // check if the connection is really in the state required for the action
    if (result)
        return;
    // we detected an error. Throw an exception.
    // query again, this time fetch the state so we can display an informaitive error message
    queryString = sparqlPrefix + "SELECT ?state WHERE { ?con wontx:hasBAState ?state }";
    binding = new QuerySolutionMap();
    binding.add("con", new ResourceImpl(fromCon.toString()));
    query = QueryFactory.create(queryString);
    qExec = QueryExecutionFactory.create(query, dataModel, binding);
    ResultSet res = qExec.execSelect();
    if (!res.hasNext()) {
        throw new IllegalStateException("connection state of connection " + fromCon + " does " + "not allow next action " + action + ". Could not determine actual connection state: not found");
    }
    QuerySolution solution = res.next();
    RDFNode state = solution.get("state");
    throw new IllegalStateException("connection state " + state + " of connection " + fromCon + " does " + "not allow next action " + action);
}
Also used : LinkedDataSource(won.protocol.util.linkeddata.LinkedDataSource) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 4 with ResourceImpl

use of org.apache.jena.rdf.model.impl.ResourceImpl in project webofneeds by researchstudio-sat.

the class WonMessage method getAttachments.

/**
 * Returns all content graphs that are attachments, including their signature graphs.
 *
 * @return
 */
public synchronized List<AttachmentHolder> getAttachments() {
    if (this.attachmentHolders != null) {
        return this.attachmentHolders;
    }
    final List<String> envelopeGraphUris = getEnvelopeGraphURIs();
    List<AttachmentHolder> newAttachmentHolders = new ArrayList<>();
    String queryString = "prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>\n" + "prefix xsd:   <http://www.w3.org/2001/XMLSchema#>\n" + "prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "prefix won:   <http://purl.org/webofneeds/model#>\n" + "prefix msg:   <http://purl.org/webofneeds/message#>\n" + "prefix sig:   <http://icp.it-risk.iwvi.uni-koblenz.de/ontologies/signature.owl#>\n" + "\n" + "select ?attachmentSigGraphUri ?attachmentGraphUri ?envelopeGraphUri ?attachmentDestinationUri where { \n" + "graph ?attachmentSigGraphUri {?attachmentSigGraphUri " + "              a sig:Signature; \n" + "              msg:hasSignedGraph ?attachmentGraphUri.\n" + "}\n" + "graph ?envelopeGraphUri {?envelopeGraphUri rdf:type msg:EnvelopeGraph.  \n" + "    ?messageUri msg:hasAttachment ?attachmentData. \n" + "?attachmentData msg:hasDestinationUri ?attachmentDestinationUri; \n" + "                msg:hasAttachmentGraphUri ?attachmentGraphUri.\n" + "}\n" + "}";
    Query query = QueryFactory.create(queryString);
    QuerySolutionMap initialBinding = new QuerySolutionMap();
    initialBinding.add("messageUri", new ResourceImpl(getMessageURI().toString()));
    try (QueryExecution queryExecution = QueryExecutionFactory.create(query, completeDataset)) {
        queryExecution.getContext().set(TDB.symUnionDefaultGraph, true);
        ResultSet result = queryExecution.execSelect();
        while (result.hasNext()) {
            QuerySolution solution = result.nextSolution();
            String envelopeGraphUri = solution.getResource("envelopeGraphUri").getURI();
            if (!envelopeGraphUris.contains(envelopeGraphUri)) {
                logger.warn("found resource {} of type msg:EnvelopeGraph that is not the URI of an envelope graph in message {}", envelopeGraphUri, this.messageURI);
                continue;
            }
            String sigGraphUri = solution.getResource("attachmentSigGraphUri").getURI().toString();
            String attachmentGraphUri = solution.getResource("attachmentGraphUri").getURI();
            String attachmentSigGraphUri = solution.getResource("attachmentSigGraphUri").getURI();
            String attachmentDestinationUri = solution.getResource("attachmentDestinationUri").getURI();
            Dataset attachmentDataset = DatasetFactory.createGeneral();
            attachmentDataset.addNamedModel(attachmentGraphUri, this.completeDataset.getNamedModel(attachmentGraphUri));
            attachmentDataset.addNamedModel(attachmentSigGraphUri, this.completeDataset.getNamedModel(attachmentSigGraphUri));
            AttachmentHolder attachmentHolder = new AttachmentHolder(URI.create(attachmentDestinationUri), attachmentDataset);
            newAttachmentHolders.add(attachmentHolder);
        }
    } catch (Exception e) {
        throw e;
    }
    this.attachmentHolders = newAttachmentHolders;
    return newAttachmentHolders;
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl)

Example 5 with ResourceImpl

use of org.apache.jena.rdf.model.impl.ResourceImpl in project webofneeds by researchstudio-sat.

the class GraphBlendingIterator method next.

@Override
public Model next() {
    if (!hasNext()) {
        throw new NoSuchElementException("No more elements available");
    }
    // add all triples together in one graph
    Model blendedModel = ModelFactory.createDefaultModel();
    blendedModel.setNsPrefixes(dataGraph1.getNsPrefixMap());
    blendedModel.setNsPrefixes(dataGraph2.getNsPrefixMap());
    blendedModel.add(dataGraph1.listStatements());
    blendedModel.add(dataGraph2.listStatements());
    int blendingIndex = 0;
    for (int i = 0; i < blendingResourceUriPairs.size(); i++) {
        // check which bits are set in the current powerSetIndex and blend the corresponding Resource pairs
        if ((powerSetIndex & (1 << i)) > 0) {
            // find a name that is not used in the blended model yet
            String blendedResourceUri;
            do {
                blendingIndex++;
                blendedResourceUri = blendingUriPrefix + blendingIndex;
            } while (blendedModel.containsResource(new ResourceImpl(blendedResourceUri)));
            // blend the resources by renaming them
            Pair<String, String> blendingPair = blendingResourceUriPairs.get(i);
            ResourceUtils.renameResource(blendedModel.getResource(blendingPair.getLeft()), blendedResourceUri);
            ResourceUtils.renameResource(blendedModel.getResource(blendingPair.getRight()), blendedResourceUri);
        }
    }
    // increase the power set index to the next valid index and return the blended model
    powerSetIndex++;
    powerSetIndex = getNextValidPowerSetIndex();
    return blendedModel;
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) Model(org.apache.jena.rdf.model.Model)

Aggregations

ResourceImpl (org.apache.jena.rdf.model.impl.ResourceImpl)8 Logger (ch.qos.logback.classic.Logger)1 Dataset (org.apache.jena.query.Dataset)1 QuerySolution (org.apache.jena.query.QuerySolution)1 QuerySolutionMap (org.apache.jena.query.QuerySolutionMap)1 Model (org.apache.jena.rdf.model.Model)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 Test (org.junit.Test)1 StopWatch (org.springframework.util.StopWatch)1 AgreementProtocolState (won.protocol.agreement.AgreementProtocolState)1 SparqlSelectFunction (won.protocol.util.SparqlSelectFunction)1 CachingLinkedDataSource (won.protocol.util.linkeddata.CachingLinkedDataSource)1 LinkedDataSource (won.protocol.util.linkeddata.LinkedDataSource)1