In Knime I am trying to compare if a value in one column is contained within another column. I tried to do this using "LIKE" in the Rule Engine but couldn't get the wildcards to work with a column input instead of a string. E.g.
For row1 I want to check if column 1, row 1 is within column 2, row 1
For row2 I want to check if column 1, row 2 is within column 2, row 2
Like is "ABC" contained within "test ABCtest"
Does the "LIKE" in Rule Engine only allow hard coded strings for comparison? Other ideas to achieve this? Thank you for the help!
The String Manipulation node with the regexMatcher can help here, though the result will be String (with values True/False by default), so further node will be required if for example a number is required (if different String, you can use the ?/: ternary operator like == "True" ? "when true" : join("when false it was because '", $columnReference$, "' was not found")).
You can use regexMatcher like this (\Q/\E helps to avoid treating the content in Reference column as a regular expression (except when it contains \E)):
regexMatcher($text$, join(".*?\\Q", $Reference$, "\\E.*+")) == "True" ? "vrai" : "faux"
Rule engine allows wildcards with LIKE operator but it does not allow wildcards combined with columns meaning the following will work fine:
$column1$ LIKE "*test*" => "1"
The following is allowed as well but will not work fine:
$column1$ LIKE "*$column2$*" => "1"
The reason is when you got double quotes $ is not recognized so you do not get the values from column2. Instead you get same string each time: "*$column2$*" which is not what you want.
Additionally you can use indexOf() function in String Manipulation or Column Expressions node that will return the first position of string value from column1 in column2. If not found the function will return -1. Follow it with Rule Engine node to add appropriate indication.
Related
I use neo4j-rest-binding API to develop, but I face a problem when using parameters of RestCypherQueryEngine.
QueryResult<Map<String,Object>> result = engine.query("MATCH (n:{label}) RETURN n", MapUtil.map("label", label));
label is the parameter I assign in the map structure, but it has an error:
org.neo4j.rest.graphdb.RestResultException: Invalid input '{': expected whitespace or an identifier (line 1, column 10)
"MATCH (n:{label}) RETURN n"
^ at
SyntaxException
org.neo4j.cypher.internal.compiler.v2_0.parser.CypherParser$$anonfun$parse$1.apply(CypherParser.scala:51)
org.neo4j.cypher.internal.compiler.v2_0.parser.CypherParser$$anonfun$parse$1.apply(CypherParser.scala:41)
...
I can use another method to solve this problem:
QueryResult<Map<String,Object>> result = engine.query("MATCH (n:" + label +") RETURN n", null);
But I think the above method is not appropriate when I want to pass multiple parameters.
:{ is a syntactical error. As the exception tells you, Cypher expects an identifier after a colon - namely, the name of a label - and an identifier (as in most languages) cannot contain a bracket.
It sounds like you're confused about the difference between labels and parameters:
The following would be valid: MATCH (n:employee{name:"foo"}) Here, employee is a label. You can apply an arbitrary number of labels delimited by colons. {name:"foo"} is a parameter block - note that it contains both the field you want to match and the value. So, this query will return all nodes labelled employee with a name value of "foo". MATCH (n:employee:custodian{name:"foo"}) will give you all employees who are custodians named "foo".
If you want all nodes with a name value of "foo", use MATCH (n {name:"foo"}) (note the absence of a colon).
Edit (responding to your comment) There are two differences between your query and the one in the example you're referring to, start n=node({id}) return n is, obviously, a START clause, which do very different things and have different syntactical rules from MATCH clauses: The id in ({id)} is simply a value to look up in an index. In a MATCH clause, what goes inside a { } block are key-value pairs, as is explained above. Inside a parameter block (i.e. a set of braces), colons are used to separate keys from values. A colon outside the brackets in a MATCH clause are used to separate labels which are different different things entirely.
The second difference is that, if you look more closely at the START clause, there is a parenthesis separating the colon from the bracket. :{ is never okay, which is what your error message is telling you.
I am trying to do a sort of nested Neo4j query in Java, which first labels a subset of nodes and then tries to match certain patterns among them. More specifically it is like combining 2 queries of this type:
1 - MATCH (n)-[r:RELATIONSHIP*1..3]->(m) set m:LABEL
2 - MATCH (p:LABEL)-[r2:RELATIONSHIP]->(q:OTHERLABEL) where r2.time<100 return p,r2,q
Is there a way I can merge these two query in only one using the Java function engine.execute() ?
'p' in query #2 will, in general, correspond to a superset of 'm' in query #1. If that is your intention, then the following should work. Notice that the 2 MATCH statements have no common variables, but a WITH is required by the Cypher syntax, so I arbitrarily picked the variable 'm' to pass to the second MATCH (even though it will be ignored).
MATCH (n)-[r:RELATIONSHIP*1..3]->(m)
SET m:LABEL
WITH m
MATCH (p:LABEL)-[r2:RELATIONSHIP]->(q:OTHERLABEL)
WHERE r2.time<100
RETURN p,r2,q;
If you intend 'm' and ''p' to be the exactly the same, then just replace '(p:LABEL)' with '(m)':
MATCH (n)-[r:RELATIONSHIP*1..3]->(m)
SET m:LABEL
WITH m
MATCH (m)-[r2:RELATIONSHIP]->(q:OTHERLABEL)
WHERE r2.time<100
RETURN m,r2,q;
SQLite statement 'abc' LIKE 'ABCd' will return true. So my question is how to make an SQLite query that will return only exact record matches for a particular query.
The LIKE operator has two modes that can be set by a pragma. The default mode is for LIKE comparisons to be insensitive to differences of case for latin1 characters. Thus, by default, the following expression is true:
'a' LIKE 'A'
But if the case_sensitive_like pragma is enabled as follows:
PRAGMA case_sensitive_like=ON;
Then the LIKE operator pays attention to case and the example above would evaluate to false.
for exact record match you need to use = sign.
ex : abc = abc.
and if you want all records which contain abc words. You need to write
abc like '%abc%' in your sqllite query.
I am using compass based indexing on my project. Now in one of the scenario I have field values something like 'dummy#value'. So if I am trying to search with any of the value which contains '#' character, its returning 0 rows..
For e.g.
DummyTable
id field_name
----------------
1 dummy#value
2 otherVal1
3 otherVal2
Query
+(+alias:DummyTable +field_name:dummy#value*) +(alias:DummyTable)
returning 0 rows, whereas
+(+alias:DummyTable +field_name:dummy*) +(alias:DummyTable)
returning 1 row..
I don't think # is a special character so I'm surprised this isn't working for you. You could try escaping the character using \#.
Another option could be to surround the term in quotes
Good luck
I was required to annotate the field declaration as
NOT_ANALYZED : (Index the property's value without using an Analyzer, so it can be searched)
#SearchableProperty(index=Index.NOT_ANALYZED)
private String field_name;
My application uses JPA to access the backend database.
I have a Java class mapped to a table. The class has a string field (called status) that consists of a series of "0"s and "1"s. I need to select a few records based on the field's second character. Here is what I can do without using JPA (I am using MS SQLServer).
SELECT * FROM Machines where SUBSTRING(status, 2, 1) = '1'
How can I do it using JPA?
There is a SUBSTRING function in JPA:
http://download.oracle.com/otn-pub/jcp/persistence-2.0-fr-eval-oth-JSpec/persistence-2_0-final-spec.pdf
4.6.17.2.1 "String functions"
(...)
SUBSTRING(string_primary, simple_arithmetic_expression [, simple_arithmetic_expression])
(...)
The second and third arguments of the SUBSTRING function denote the starting position and
length of the substring to be returned. These arguments are integers.
The third argument is optional. If it is not specified, the substring
from the start position to the end of the string is returned. The
first position of a string is denoted by 1. The SUBSTRING function
returns a string.
JPQL has the SUBSTRING(..) function as well: see here. So it will be the same as in the native query.
When JPA doesn't support some function that you need, you can make a native query and map the result to a pojo.
JPQL has a substring function which can be used to trim entities. Make sure you use entity names in your query and also note that the substring function is not zero indexed.
SELECT * FROM Machines m where SUBSTRING(m.status, 2, 1) = '1'