@Override public Literal assertPropertyToLiteral(@Simple("body.nodeName") String nodeName, @Simple("body.property") String property, @Simple("body.objectType") String objectType, @Simple("body.object") Object object, @Simple("body.truthValue") float[] truthValue, @Simple("body.assertionTime") DateTime assertionTime, @Simple("body.asserterNodeName") String asserterNodeName) { //final String relationship = property.replace(':', '_'); final String cypher = "MATCH (n:owl_Thing {nn: {nn}}) WHERE n._partition IN ['lumen_yago', 'lumen_platform', 'lumen_var']\n" + "MATCH (p:rdf_Property {nn: {property}}) WHERE p._partition IN ['lumen_yago', 'lumen_platform', 'lumen_var']\n" + "MERGE (n) <-[:rdf_subject]- (literal:rdfs_Literal {t: {type}, v: {value}, _partition: {partitionKey}}) -[:rdf_predicate]-> (p)\n" + "SET literal.tv={tv}\n" + "RETURN literal"; final ImmutableMap<String, Object> params = ImmutableMap.<String, Object>builder() .put("partitionKey", PartitionKey.lumen_var) .put("nn", nodeName) .put("property", property) .put("type", objectType) .put("value", object) .put("tv", truthValue) .build(); log.trace("assertPropertyToLiteral {} using {}", params, cypher); final Literal literal = neo4j.queryForObject(Literal.class, cypher, params); Preconditions.checkNotNull(literal, "Cannot assert literal \"%s\":%s because either thing '%s' or property '%s' not found", object, objectType, nodeName, property); return literal; }
@Override public void configure() throws Exception { errorHandler(new LoggingErrorHandlerBuilder(log)); from("direct:" + LumenChannel.PERSISTENCE_FACT.key()) .process(exchange -> { final BeanInvocation invocation = exchange.getIn().getBody(BeanInvocation.class); final FactRequest factRequest = new FactRequest(); factRequest.setOperation(FactServiceOperation.valueOf(invocation.getMethod().getName())); log.info("Invoking {} {}", invocation.getMethod(), invocation.getArgs()); for (int i = 0; i < invocation.getArgs().length; i++) { final String simpleExpr = invocation.getMethod().getParameters()[i].getAnnotation(Simple.class).value(); final String paramName = StringUtils.substringAfter(simpleExpr, "body."); PropertyUtils.setProperty(factRequest, paramName, invocation.getArgs()[i]); } exchange.getIn().setBody(factRequest); exchange.setPattern(ExchangePattern.InOut); //exchange.getIn().setHeader(RabbitMQConstants.REPLY_TO, ); }) .bean(toJson) .to("rabbitmq://localhost/amq.topic?connectionFactory=#amqpConnFactory&exchangeType=topic&autoDelete=false&skipQueueDeclare=true&routingKey=" + LumenChannel.PERSISTENCE_FACT.key()) .to("log:REPLY." + LumenChannel.PERSISTENCE_FACT.key()); }
@Override public ThingLabel assertLabel(@Simple("body.nodeName") String nodeName, @Simple("body.property") String property, @Simple("body.label") String label, String inLanguage, @Simple("body.truthValue") float[] truthValue, @Simple("body.assertionTime") DateTime assertionTime, @Simple("body.asserterNodeName") String asserterNodeName) { final String metaphone = ThingLabel.METAPHONE.encode(label); final String relationship = property.replace(':', '_'); final String cypher = "MATCH (n:owl_Thing {nn: {nn}}) WHERE n._partition IN ['lumen_yago', 'lumen_platform', 'lumen_var']\n" + "MERGE (n) -[:" + relationship + "]-> (label:lumen_Label {l: {inLanguage}, v: {value}, _partition: {partitionKey}})\n" + "SET label.tv={tv}, label.m={metaphone}\n" + "RETURN label"; // @Query("MATCH (n:owl_Thing {nn: {nn}}) WHERE n._partition IN ['lumen_yago', 'lumen_platform', 'lumen_var']\n" + // "MERGE (n) -[:{property}]-> (label:lumen_Label {l: {inLanguage}, v: {value}, _partition: {partitionKey}})\n" + // "SET label.tv={tv}, label.m={metaphone}\n" + // "RETURN label") // ThingLabel assertLabel(@Param("partitionKey") PartitionKey partitionKey, // @Param("nn") String nn, // @Param("property") String property, // @Param("inLanguage") String inLanguage, // @Param("value") String value, // @Param("tv") float[] tv, // @Param("metaphone") String metaphone); // return thingLabelRepo.assertLabel(PartitionKey.lumen_var, nodeName, relationship, inLanguage, label, truthValue, metaphone); final ImmutableMap<String, Object> params = ImmutableMap.<String, Object>builder() .put("partitionKey", PartitionKey.lumen_var) .put("nn", nodeName) .put("property", property) .put("inLanguage", inLanguage) .put("value", label) .put("tv", truthValue) .put("metaphone", metaphone) .build(); log.trace("assertLabel {} using {}", params, cypher); final ThingLabel labelNode = neo4j.queryForObject(ThingLabel.class, cypher, params); Preconditions.checkNotNull(labelNode, "Cannot assert %s \"%s\"@%s because thing '%s' not found", property, label, inLanguage, nodeName); return labelNode; }
@Override public Fact getProperty(@Simple("body.nodeName") String nodeName, @Simple("body.property") String property) { final Literal literal = neo4j.queryForObject(Literal.class, "MATCH (s:schema_Thing {nn: {nodeName}}) <-[:rdf_subject]- (l:rdfs_Literal) -[:rdf_predicate]-> (p:rdf_Property {nn: {property}})" + " WHERE s._partition IN {partitions} AND p._partition IN {partitions}" + " RETURN l LIMIT 1", ImmutableMap.of("nodeName", nodeName, "property", property, "partitions", new String[]{PartitionKey.lumen_yago.name(), PartitionKey.lumen_var.name()})); if (literal != null) { // final Literal literal = (Literal) result.get(0).get("l"); // final Thing subject = (Thing) result.get(0).get("s"); // final SemanticProperty predicate = (SemanticProperty) result.get(0).get("p"); final Thing subject = literal.getSubject(); // final SemanticProperty predicate = literal.getPredicate(); final Fact fact = new Fact(); fact.setSubject(subject); fact.setProperty(property); if ("xsd:string".equals(literal.getType())) { fact.setKind(FactKind.STRING); fact.setObjectAsString((String) literal.getValue()); } else if ("xs:date".equals(literal.getType())) { fact.setKind(FactKind.LOCALDATE); fact.setObjectAsLocalDate(new LocalDate(literal.getValue())); } else { throw new LumenPersistenceException(String.format("Unknown Literal type: %s with value '%s' for node %s", literal.getType(), literal.getValue(), literal.getGid())); } log.info("getProperty {} {} returns {}", nodeName, property, fact); return fact; } else { log.info("getProperty {} {} returns null", nodeName, property); return null; } }
@Handler public Map getProcessVariables(@Body String body, @Header(Exchange.FILE_NAME) String filename, @Simple("${date:now:yyyy-MM-dd kk:mm:ss}") String timestamp) { Map<String, Object> variables = new HashMap<String, Object>(); variables.put("message", body); variables.put("orderid", filename); variables.put("timestamp", timestamp); return variables; }
public static void throwStatusError( @Simple("${body[STATUS]}") String status, @Simple("${body[MESSAGE]}") String message ) throws Exception { throw new Exception(MessageFormat.format("Status {0} - {1}", status, message)); }
public String sayHello(@Header("name") String name, @Simple("${sys.user.country}") String country) { return "Hello " + name + ", how are you? You are from: " + country; }
public static String hello(@Simple("${body}") String body, @Simple("${body}") String body2) { // we should be able to read the stream multiple times return body.toLowerCase() + body2.toUpperCase(); }
public void foo(@Simple("${header.foo}") String bar) { this.bar = bar; LOG.info("foo() method called with: " + bar); }
@Handler public void foo(@Simple("${header.foo}") String bar) { this.bar = bar; LOG.info("foo() method called with: " + bar); }
public void read(String body, @Simple("${header.foo} != null") boolean foo) { this.body = body; this.foo = foo; }
public void read(String body, @Simple("${header.foo}") String foo) { this.foo = foo; this.body = body; LOG.info("read() method called on " + this); }
/** * Assert a property to literal. * @param nodeName Subject's node name, e.g. {@code lumen:Hendy_Irawan}. * @param property Property's QName, e.g. {@code rdf:type}. * @param objectType Literal type, e.g. {@code xsd:string}. * @param object Literal object, can be string or integer or boolean or float. * @param truthValue Truth value of the assertion, relative to asserter. * @param assertionTime Time of the assertion. * @param asserterNodeName Node name of the person who asserts this. * @return */ Literal assertPropertyToLiteral( @Simple("body.nodeName") String nodeName, @Simple("body.property") String property, @Simple("body.objectType") String objectType, @Simple("body.object") Object object, @Simple("body.truthValue") float[] truthValue, @Simple("body.assertionTime") DateTime assertionTime, @Simple("body.asserterNodeName") String asserterNodeName);
/** * Matches {@code upLabel} with known {@link org.lskk.lumen.persistence.neo4j.Thing}s based on active contexts. * @param upLabel Label to match, free-form. Fuzzy string matching will also be attempted, * which will be reflected in {@link MatchingThing#getConfidence()}. * @param inLanguage Language of the provided label. * @param contexts Contexts of the match. Key is node name, value is non-normalized confidence [0..1]. * @return Matching things, sorted descending by confidence, limited to {@link #MAX_RESULTS}. */ MatchingThings match(@Simple("body.upLabel") String upLabel, @Simple("body.inLanguage") Locale inLanguage, @Simple("body.contexts") Map<String, Float> contexts);
/** * Describes a thing. * @param nodeName * @return */ Thing describeThing(@Simple("body.nodeName") String nodeName);
/** * Asserts a thing and gives it a preferred label. * @param nodeName * @param upLabel * @param inLanguage Language of the {@code upLabel}. * @param isPrefLabel If {@code true}, this will replace the {@link Thing}'s current {@code prefLabel}. * Otherwise, will just add a new {@link org.lskk.lumen.persistence.jpa.YagoLabel}. */ Thing assertThing(@Simple("body.nodeName") String nodeName, @Simple("body.upLabel") String upLabel, @Simple("body.inLanguage") Locale inLanguage, @Simple("body.isPrefLabel") boolean isPrefLabel);
/** * Unasserts a thing. * @param nodeName */ Thing unassertThing(@Simple("body.nodeName") String nodeName);
/** * Assert a property to another thing, i.e. fact. * @param nodeName Subject's node name, e.g. {@code lumen:Hendy_Irawan}. * @param property Property's QName, e.g. {@code rdf:type}. * @param objectNodeName Object's node name, e.g. {@code yago:wordnet_person_100007846}. * @param truthValue Truth value of the assertion, relative to asserter. * @param assertionTime Time of the assertion. * @param asserterNodeName Node name of the person who asserts this. * @return */ Statement assertPropertyToThing(@Simple("body.nodeName") String nodeName, @Simple("body.property") String property, @Simple("body.objectNodeName") String objectNodeName, @Simple("body.truthValue") float[] truthValue, @Simple("body.assertionTime") DateTime assertionTime, @Simple("body.asserterNodeName") String asserterNodeName);
/** * Assert a property to label. * @param nodeName Subject's node name, e.g. {@code lumen:Hendy_Irawan}. * @param property Property's QName, e.g. {@code rdf:type}. * @param label Label. * @param inLanguage * @param truthValue Truth value of the assertion, relative to asserter. * @param assertionTime Time of the assertion. * @param asserterNodeName Node name of the person who asserts this. @return * */ ThingLabel assertLabel( @Simple("body.nodeName") String nodeName, @Simple("body.property") String property, @Simple("body.label") String label, @Simple("body.inLanguage") String inLanguage, @Simple("body.truthValue") float[] truthValue, @Simple("body.assertionTime") DateTime assertionTime, @Simple("body.asserterNodeName") String asserterNodeName);
/** * Get a single fact or literal property. */ Fact getProperty(@Simple("body.nodeName") String nodeName, @Simple("body.property") String property);