Search in sources :

Example 6 with ResourceImpl

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

the class WonMessageQueryBuilder method senderConnection.

public WonMessageQueryBuilder senderConnection(URI senderConnection) {
    QuerySolutionMap initialBinding = new QuerySolutionMap();
    initialBinding.add("senderConnection", new ResourceImpl(senderConnection.toString()));
    delegate.addInitialBindings(initialBinding);
    return this;
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap)

Example 7 with ResourceImpl

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

the class NeedModelWrapper method copyNode.

private Resource copyNode(Resource node) {
    if (node.isAnon())
        return node.getModel().createResource();
    int i = 0;
    String uri = node.getURI() + RandomStringUtils.randomAlphanumeric(4);
    String newUri = uri + "_" + i;
    while (node.getModel().containsResource(new ResourceImpl(newUri))) {
        i++;
        newUri = uri + "_" + i;
    }
    return node.getModel().getResource(newUri);
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl)

Example 8 with ResourceImpl

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

the class WonConversationUtilsTest method main.

public static void main(String... args) throws Exception {
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.INFO);
    // Dataset input = loadDataset("/won/utils/agreement/input/one-agreement-one-cancellation.trig");
    Dataset input = loadDataset("/won/utils/conversationutils/input/longer-conversation.trig");
    SparqlSelectFunction<QuerySolution> selectfunction = new SparqlSelectFunction<>("/conversation/messagesForHighlevelProtocols.rq", x -> x).addOrderBy("distance", Query.ORDER_ASCENDING).addInitialBinding("senderOfFirstMessage", new ResourceImpl("https://localhost:8443/won/resource/need/4517796920802783000"));
    StopWatch sw = new StopWatch();
    sw.start();
    selectfunction.apply(input).forEach(x -> System.out.println("solution:" + x.toString()));
    sw.stop();
    System.out.println("query took: " + sw.getLastTaskTimeMillis() / 1000d + " seconds ");
    // Thread.currentThread().sleep(30000);
    sw.start();
    AgreementProtocolState state = AgreementProtocolState.of(input);
    sw.stop();
    RDFDataMgr.write(System.out, state.getAgreements(), Lang.TRIG);
    System.out.println("Analyzing the state of agreement protocol took: " + sw.getLastTaskTimeMillis() / 1000d + " seconds ");
    System.out.println(state.getAgreementProtocolUris());
    System.out.println(state.getEffects(URI.create("https://localhost:8443/won/resource/event/grj35bbhnkcrlfc72pqo")));
/*
		RdfUtils.Pair<Dataset> diff = RdfUtils.diff(input, output);
		if (!(diff.getFirst().isEmpty() && diff.getSecond().isEmpty())) {
			System.out.println("diff - only in input:");
			RDFDataMgr.write(System.out, diff.getFirst(), Lang.TRIG);
			System.out.println("diff - only in output:");
			RDFDataMgr.write(System.out, diff.getSecond(), Lang.TRIG);
		} else {
			System.out.println("input and output are equal");
		}
		*/
// Dataset output = HighlevelProtocols.getProposals(input);
// RDFDataMgr.write(System.out, output, Lang.TRIG);
// initialBinding.add("senderNeed", new ResourceImpl("https://localhost:8443/won/resource/need/7820503869697675000"));
// initialBinding.add("senderConnection", new ResourceImpl("https://localhost:8443/won/resource/connection/4t9deo4t6bqx83jxk5ex"));
// URI uri = WonConversationUtils.getLatestMessageOfNeed(input, URI.create("https://localhost:8443/won/resource/need/7820503869697675000"));
// URI uri = WonConversationUtils.getLatestMessageOfNeed(input, URI.create("https://192.168.124.49:8443/won/resource/need/z35td13ftmn5k1hzella"));
// System.out.println("uri: " + uri);
/*
		List<QuerySolution> actual = WonConversationQueryBuilder.getBuilder((x -> x))
				//.senderNeed(URI.create("https://localhost:8443/won/resource/need/7820503869697675000"))
				.newestFirst()
				.noResponses()
				.build()
				.apply(input);
		*/
// System.out.println("actual: \n" + actual.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
/*
		URI uri = WonConversationUtils.getLatestProposesMessageOfNeed(input, URI.create("https://localhost:8443/won/resource/need/7820503869697675000"));
		System.out.println("uri: " + uri);
		uri = WonConversationUtils.getLatestAcceptsMessageOfNeed(input, URI.create("https://localhost:8443/won/resource/need/7820503869697675000"));
		System.out.println("uri: " + uri);*/
}
Also used : ResourceImpl(org.apache.jena.rdf.model.impl.ResourceImpl) QuerySolution(org.apache.jena.query.QuerySolution) Dataset(org.apache.jena.query.Dataset) SparqlSelectFunction(won.protocol.util.SparqlSelectFunction) AgreementProtocolState(won.protocol.agreement.AgreementProtocolState) Logger(ch.qos.logback.classic.Logger) StopWatch(org.springframework.util.StopWatch)

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