Search in sources :

Example 36 with PrefixMapping

use of org.apache.jena.shared.PrefixMapping in project webofneeds by researchstudio-sat.

the class WonLinkedDataUtils method getConversationDataset.

public static Dataset getConversationDataset(URI connectionURI, URI requesterWebId, LinkedDataSource linkedDataSource) {
    assert linkedDataSource != null : "linkedDataSource must not be null";
    // depth 3 from connection gives us the messages in the conversation
    int depth = 5;
    int maxRequests = 1000;
    List<Path> propertyPaths = new ArrayList<>();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.withDefaultMappings(PrefixMapping.Standard);
    pmap.setNsPrefix("won", WON.getURI());
    pmap.setNsPrefix("msg", WONMSG.getURI());
    propertyPaths.add(PathParser.parse("won:messageContainer", pmap));
    propertyPaths.add(PathParser.parse("won:messageContainer/rdfs:member", pmap));
    propertyPaths.add(PathParser.parse("won:targetConnection", pmap));
    propertyPaths.add(PathParser.parse("won:targetConnection/won:messageContainer", pmap));
    propertyPaths.add(PathParser.parse("won:targetConnection/won:messageContainer/rdfs:member", pmap));
    return linkedDataSource.getDataForResourceWithPropertyPath(connectionURI, requesterWebId, propertyPaths, maxRequests, depth);
}
Also used : Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 37 with PrefixMapping

use of org.apache.jena.shared.PrefixMapping in project webofneeds by researchstudio-sat.

the class WonLinkedDataUtils method getConversationAndAtomsDataset.

public static Dataset getConversationAndAtomsDataset(URI connectionURI, URI requesterWebId, LinkedDataSource linkedDataSource) {
    Objects.requireNonNull(linkedDataSource);
    Objects.requireNonNull(connectionURI);
    int depth = 5;
    int maxRequests = 1000;
    List<Path> propertyPaths = new ArrayList<>();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.withDefaultMappings(PrefixMapping.Standard);
    pmap.setNsPrefix("won", WON.getURI());
    pmap.setNsPrefix("msg", WONMSG.getURI());
    propertyPaths.add(PathParser.parse("won:messageContainer", pmap));
    propertyPaths.add(PathParser.parse("won:messageContainer/rdfs:member", pmap));
    propertyPaths.add(PathParser.parse("won:messageContainer/rdfs:member/msg:previousMessage", pmap));
    return linkedDataSource.getDataForResourceWithPropertyPath(connectionURI, requesterWebId, propertyPaths, maxRequests, depth);
}
Also used : Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 38 with PrefixMapping

use of org.apache.jena.shared.PrefixMapping in project webofneeds by researchstudio-sat.

the class Prefixer method getPrefixes.

public static PrefixMapping getPrefixes() {
    PrefixMapping prefixMapping = new PrefixMappingImpl();
    prefixMapping.setNsPrefix(WON.DEFAULT_PREFIX, WON.getURI());
    prefixMapping.setNsPrefix(WONMSG.DEFAULT_PREFIX, WONMSG.getURI());
    prefixMapping.setNsPrefix(WONCON.DEFAULT_PREFIX, WONCON.getURI());
    prefixMapping.setNsPrefix(WONMATCH.DEFAULT_PREFIX, WONMATCH.getURI());
    prefixMapping.setNsPrefix(WXCHAT.DEFAULT_PREFIX, WXCHAT.BASE_URI);
    prefixMapping.setNsPrefix(WXGROUP.DEFAULT_PREFIX, WXGROUP.BASE_URI);
    prefixMapping.setNsPrefix(WXHOLD.DEFAULT_PREFIX, WXHOLD.BASE_URI);
    prefixMapping.setNsPrefix(WXREVIEW.DEFAULT_PREFIX, WXREVIEW.BASE_URI);
    prefixMapping.setNsPrefix(WXBUDDY.DEFAULT_PREFIX, WXBUDDY.BASE_URI);
    prefixMapping.setNsPrefix(WXVALUEFLOWS.DEFAULT_PREFIX, WXVALUEFLOWS.BASE_URI);
    prefixMapping.setNsPrefix("vf", "https://w3id.org/valueflows#");
    prefixMapping.setNsPrefix("om2", "http://www.ontology-of-units-of-measure.org/resource/om-2/");
    prefixMapping.setNsPrefix("demo", "https://w3id.org/won/ext/demo#");
    prefixMapping.setNsPrefix("wx-bot", "https://w3id.org/won/ext/bot#");
    prefixMapping.setNsPrefix("wxs", "https://w3id.org/won/ext/schema#");
    prefixMapping.setNsPrefix("pogo", "https://w3id.org/won/ext/pogo#");
    prefixMapping.setNsPrefix(CERT.DEFAULT_PREFIX, CERT.getURI());
    prefixMapping.setNsPrefix("rdf", RDF.getURI());
    prefixMapping.setNsPrefix("rdfs", RDFS.getURI());
    prefixMapping.setNsPrefix("xsd", XSD.getURI());
    prefixMapping.setNsPrefix("dc", DC.getURI());
    prefixMapping.setNsPrefix("dct", DCTerms.getURI());
    prefixMapping.setNsPrefix("schema", SCHEMA.getURI());
    prefixMapping.setNsPrefix("sh", "http://www.w3.org/ns/shacl#");
    prefixMapping.setNsPrefix("rdfg", "http://www.w3.org/2004/03/trix/rdfg-1/");
    prefixMapping.setNsPrefix("owl", OWL.getURI());
    prefixMapping.setNsPrefix("vann", "http://purl.org/vocab/vann/");
    return prefixMapping;
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Example 39 with PrefixMapping

use of org.apache.jena.shared.PrefixMapping in project webofneeds by researchstudio-sat.

the class CrawlConnectionDataBehaviour method onActivate.

@Override
protected void onActivate(Optional<Object> message) {
    logger.debug("activating crawling connection data for connection {}", command.getConnectionURI());
    logger.debug("will deactivate automatically after " + abortTimeout);
    LinkedDataSource linkedDataSource = context.getLinkedDataSource();
    if (linkedDataSource instanceof CachingLinkedDataSource) {
        URI toInvalidate = WonRelativeUriHelper.createMessageContainerURIForConnection(command.getConnectionURI());
        ((CachingLinkedDataSource) linkedDataSource).invalidate(toInvalidate);
        ((CachingLinkedDataSource) linkedDataSource).invalidate(toInvalidate, command.getAtomURI());
    }
    context.getTaskScheduler().schedule(this::deactivate, new Date(System.currentTimeMillis() + abortTimeout.toMillis()));
    List<Path> propertyPaths = new ArrayList<>();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.withDefaultMappings(PrefixMapping.Standard);
    pmap.setNsPrefix("won", WON.getURI());
    pmap.setNsPrefix("msg", WONMSG.getURI());
    propertyPaths.add(PathParser.parse("won:messageContainer", pmap));
    propertyPaths.add(PathParser.parse("won:messageContainer/rdfs:member", pmap));
    CrawlCommandEvent crawlAtomCommandEvent = new CrawlCommandEvent(command.getAtomURI(), command.getAtomURI(), propertyPaths, 10000, 5);
    propertyPaths = new ArrayList<>();
    propertyPaths.add(PathParser.parse("won:messageContainer", pmap));
    propertyPaths.add(PathParser.parse("won:messageContainer/rdfs:member", pmap));
    propertyPaths.add(PathParser.parse("won:messageContainer/rdfs:member/msg:correspondingRemoteMessage", pmap));
    propertyPaths.add(PathParser.parse("won:targetAtom", pmap));
    propertyPaths.add(PathParser.parse("won:targetConnection", pmap));
    CrawlCommandEvent crawlConnectionCommandEvent = new CrawlCommandEvent(command.getAtomURI(), command.getConnectionURI(), propertyPaths, 10000, 5);
    Dataset crawledData = DatasetFactory.createGeneral();
    // add crawlcommand listener
    this.subscribeWithAutoCleanup(CrawlCommandEvent.class, new ActionOnEventListener(context, new OrFilter(new SameEventFilter(crawlAtomCommandEvent), new SameEventFilter(crawlConnectionCommandEvent)), new CrawlAction(context)));
    // when the first crawl succeeds, start the second
    this.subscribeWithAutoCleanup(CrawlCommandSuccessEvent.class, new ActionOnEventListener(context, new CommandResultFilter(crawlAtomCommandEvent), new BaseEventBotAction(context) {

        @Override
        protected void doRun(Event event, EventListener executingListener) throws Exception {
            logger.debug("finished crawling atom data. ");
            Dataset dataset = ((CrawlCommandSuccessEvent) event).getCrawledData();
            RdfUtils.addDatasetToDataset(crawledData, dataset);
            // now crawl connection data
            context.getEventBus().publish(crawlConnectionCommandEvent);
        }
    }));
    // when we're done crawling, validate:
    this.subscribeWithAutoCleanup(CrawlCommandSuccessEvent.class, new ActionOnEventListener(context, new CommandResultFilter(crawlConnectionCommandEvent), new BaseEventBotAction(context) {

        @Override
        protected void doRun(Event event, EventListener executingListener) throws Exception {
            logger.debug("finished crawling atom data for connection {}", command.getConnectionURI());
            Dataset dataset = ((CrawlCommandSuccessEvent) event).getCrawledData();
            RdfUtils.addDatasetToDataset(crawledData, dataset);
            context.getEventBus().publish(new CrawlConnectionCommandSuccessEvent(command, crawledData));
            deactivate();
        }
    }));
    // when something goes wrong, abort
    this.subscribeWithAutoCleanup(CrawlCommandFailureEvent.class, new ActionOnFirstEventListener(context, new OrFilter(new CommandResultFilter(crawlConnectionCommandEvent), new CommandResultFilter(crawlAtomCommandEvent)), new BaseEventBotAction(context) {

        @Override
        protected void doRun(Event event, EventListener executingListener) throws Exception {
            CrawlCommandFailureEvent failureEvent = (CrawlCommandFailureEvent) event;
            logger.debug("crawling failed for connection {}, message: {}", command.getConnectionURI(), failureEvent.getMessage());
            context.getEventBus().publish(new CrawlConnectionCommandFailureEvent(failureEvent.getMessage(), command));
            deactivate();
        }
    }));
    // start crawling the atom - connection will be crawled when atom crawling is
    // done
    context.getEventBus().publish(crawlAtomCommandEvent);
}
Also used : SameEventFilter(won.bot.framework.eventbot.filter.impl.SameEventFilter) CrawlAction(won.bot.framework.eventbot.action.impl.crawl.CrawlAction) CrawlConnectionCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandSuccessEvent) ArrayList(java.util.ArrayList) CrawlCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandSuccessEvent) CommandResultFilter(won.bot.framework.eventbot.filter.impl.CommandResultFilter) LinkedDataSource(won.protocol.util.linkeddata.LinkedDataSource) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) URI(java.net.URI) CrawlCommandEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandEvent) ActionOnFirstEventListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) Path(org.apache.jena.sparql.path.Path) CrawlCommandFailureEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandFailureEvent) Dataset(org.apache.jena.query.Dataset) OrFilter(won.bot.framework.eventbot.filter.impl.OrFilter) CrawlConnectionCommandFailureEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandFailureEvent) Date(java.util.Date) PrefixMapping(org.apache.jena.shared.PrefixMapping) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) CrawlCommandEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandEvent) CrawlConnectionCommandFailureEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandFailureEvent) CrawlCommandFailureEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandFailureEvent) CommandResultEvent(won.bot.framework.eventbot.event.impl.cmd.CommandResultEvent) CrawlCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandSuccessEvent) CrawlConnectionCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandSuccessEvent) Event(won.bot.framework.eventbot.event.Event) CrawlConnectionCommandEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandEvent) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ActionOnFirstEventListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener)

Example 40 with PrefixMapping

use of org.apache.jena.shared.PrefixMapping in project jena by apache.

the class TestFmtUtils method getPrefixMapping.

private PrefixMapping getPrefixMapping() {
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("zz", aUri);
    return pmap;
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl)

Aggregations

PrefixMapping (org.apache.jena.shared.PrefixMapping)154 Test (org.junit.Test)47 PrefixMappingImpl (org.apache.jena.shared.impl.PrefixMappingImpl)34 Graph (org.apache.jena.graph.Graph)22 Path (org.apache.jena.sparql.path.Path)12 BaseTest (org.apache.jena.atlas.junit.BaseTest)11 Triple (org.apache.jena.graph.Triple)9 Resource (org.apache.jena.rdf.model.Resource)9 ConfigTest (org.apache.jena.tdb.ConfigTest)8 DatasetPrefixesTDB (org.apache.jena.tdb.store.DatasetPrefixesTDB)8 ContractTest (org.xenei.junit.contract.ContractTest)8 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)7 Node (org.apache.jena.graph.Node)5 Query (org.apache.jena.query.Query)5 Model (org.apache.jena.rdf.model.Model)5 PrefixMappingSDB (org.apache.jena.sdb.graph.PrefixMappingSDB)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)4 Dataset (org.apache.jena.query.Dataset)4