Using patterns in expressions with Memgraph - memgraphdb

When I run the follwing query, I get an error:
MATCH (n:NodeA)
WHERE NOT (n)-[]->(:NodeB)
RETURN n;
After executing it I receive an error:
Not yet implemented: atom expression '(n)-[]->(:NodeB)'
How can I run such query in Memgrpah?

The same query can be expressed using the OPTIONAL MATCH clause.
The clause OPTIONAL MATCH behaves the same as a regular MATCH, but when it fails to find the pattern, missing parts of the pattern will be filled with null values.
The example query would look like this:
OPTIONAL MATCH (n:NodeA)-[]->(m:NodeB)
WHERE m IS null
RETURN DISTINCT n;

Related

exctract substring from a large string under certain conditions in painless

In painless I would like to create a script which reads a keyword field called 'objldn' and extracts only five consecutive characters sometimes present in a precise position. Infact, in the keyword field 'objldn' there are a large variety of long strings among which there are some of them with a third underscore. After the third underscore, if it is present, I can fetch the consecutive 5 chars.
Whith the following lines of code I implement what I want:
def LU = doc['objldn'].value.splitOnToken('_');
return LU[3].substring(0, 5);
But the system returnes an error message "out of bounds":
Request error: array_index_out_of_bounds_exception, Index 3 out of
bounds for length 3 in "def LU =
doc['objldn'].value.splitOnToken('_'); ..." (Painless script)
error executing runtime field or scripted field on index pattern
return LU[3].substring(0, 5);
^---- HERE
may be it is due to the fact that many strings do not have the third underscore or do not even have one and therefore I need to implement firstly a IF statement which evaluates if a third underscore is in the string and only if it is present it proceeds to execute splitOnToken()... but I am not able to do it correctly. Can you help me to add the IF statement in the script please?
Why not simply checking the length of the LU array?
def LU = doc['objldn'].value.splitOnToken('_');
return LU.length >= 4 ? LU[3].substring(0, 5) : null;

How to use wildcard with a variable?

I need to evaluate the output to see if it starts with a specific sequence.
For example if Cat1 = (A)
I want to verify that the entry begins with the value of Cat1 and can contain any text after it. If so then to output that entry.
I don't exactly know how to use wildcards in conjunction with the variable to allow entries such as
(A) First assignment
(A) Second assignment
to be selected and then to be transferred.
The portion that is in question is the following in my code:
if(assign.title == ){
SpreadsheetApp.openByUrl(url).getSheetByName(shet).appendRow([assign.title, marks.assignedGrade,
assign.maxPoints]);}
}
Your issue can be solved by using Regular Expressions which essentially are special text strings used to describe a search pattern.
Therefore, if you want to search for the entries which begin with (A) and appendRow() like you mentioned above, you should use the following code snippet:
function theFunction() {
var ss = SpreadsheetApp.openByUrl("YOUR_URL").getSheetByName("YOUR_SHEET_NAME");
var regEx = /((A)).*/;
//Getting the assign & marks variables
if (assign.title.match(regEx))
appendRow([assign.title, marks.assignedGrade, assign.maxPoints]);
}
The regular expression here is represented by the var regEx = /((A)).*/; which searches for a string to see if it starts with the (A) string.
Furthermore, I suggest you take a look at these links since they might be of help:
Syntax for Regular Expressions;
Regular Expressions Tester.

MariaDB fulltext search with special chars and "word starts with"

I can do a MariaDB fulltext query which searches for the word beginning like this:
select * from mytable
where match(mycol) against ('+test*' in boolean mode)>0.0;
This finds words like "test", "tester", "testing".
If my search string contains special characters, I can put the search string in quotes:
select * from mytable
where match(mycol) against ('+"test-server"' in boolean mode)>0.0;
This will find all rows which contain the string test-server.
But it seems I cannot combine both:
select * from mytable
where match(mycol) against ('+"test-serv"*' in boolean mode)>0.0;
This results in an error:
Error: (conn:7) syntax error, unexpected $end, expecting FTS_TERM or FTS_NUMB or '*'
SQLState: 42000
ErrorCode: 1064
Placing the ´*´ in the quoted string will return no results (as expected):
select * from mytable
where match(mycol) against ('+"test-serv*"' in boolean mode)>0.0;
Does anybody know whether this is a limitation of MariaDB? Or a bug?
My MariaDB version is 10.0.31
WHERE MATCH(mycol) AGAINST('+test +serv*' IN BOOLEAN MODE)
AND mycol LIKE '%test_serv%'
The MATCH will find the desired rows plus some that are not desired. Then the LIKE will filter out the duds. Since the LIKE is being applied to only some rows, its slowness is masked.
(Granted, this does not work in all cases. And it requires some manual manipulation.)
d'Artagnan - Use
WHERE MATCH(mycol) AGAINST("+Arta*" IN BOOLEAN MODE)
AND mycol LIKE '%d\'Artagnan%'
Note that I used the suitable escaping for getting the apostrophe into the LIKE string.
So, the algorithm for your code goes something like:
Break the string into "words" the same way FULLTEXT would.
Toss any strings that are too short.
If no words are left, then you cannot use FULLTEXT and are stuck with a slow LIKE.
Stick * after the last word (or each word?).
Build the AGAINST with those word(s).
Add on AND LIKE '%...%' with the original phrase, suitably escaped.

ruby regex not working to remove class name from sql

I have:
BEFORE Gsub sql ::::
SELECT record_type.* FROM record_type WHERE (name = 'Registrars')
sql = sql.gsub(/SELECT\s+[^\(][A-Z]+\./mi,"SELECT ")
AFTER GSUB SQL ::::
SELECT record_type.* FROM record_type WHERE (name = 'Registrars')
The desired result is to remove the "record_type." from the statement:
So it should be :
SELECT * FROM record_type WHERE (name = 'Registrars')
After the regex is run.
I didn't write this, it's in the asf-soap-adaptor gem. Can someone tell me why it doesn't work, and how to fix?
I suppose it should be written like this...
sql = sql.gsub(/SELECT\s+[^\(][A-Z_]+\./mi,"SELECT ")
... as the code in the question won't match if the field name contains _ (underscore) symbol. I suppose that's why this code is in gem: it can work in some conditions (i.e., with underscoreless field names).
Still, I admit I don't understand why exactly this replacement should be done - and shouldn't it include 0-9 check as well (as, for example, 'record_id1' field still won't be matched - and replaced - by the character class in the regular expression; you may have to either expand it, like [0-9A-Z_], or just replace completely with \w).
so your before and after gsubs are the same? I can't tell you why it doesn't work if you dont tell me your expected result. Also for help with interpreting ruby regular expressions check out rubular.com

Whats the XPath equivalent to SQL In query?

I would like to know whats the XPath equivalent to SQL In query. Basically in sql i can do this:
select * from tbl1 where Id in (1,2,3,4)
so i want something similar in XPath/Xsl:
i.e.
//*[#id= IN('51417','1121','111')]
Please advice
(In XPath 2,) the = operator always works like in.
I.e. you can use
//*[#id = ('51417','1121','111')]
A solution is to write out the options as separate conditions:
//*[(#id = '51417') or (#id = '1121') or (#id = '111')]
Another, slightly less verbose solution that looks a bit like a hack, though, would be to use the contains function:
//*[contains('-51417-1121-111-', concat('-', #id, '-'))]
Literally, this means you're checking whether the value of the id attribute (preceeded and succeeded by a delimiter character) is a substring of -51417-1121-111-. Note that I am using a hyphen (-) as a delimiter of the allowable values; you can replace that with any character that will not appear in the id attribute.

Resources