use of won.protocol.util.SparqlSelectFunction 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);*/
}
Aggregations