I am trying to create a node
create (n:node0{78 : 78});
This results in an error of
Invalid input ':': expected whitespace, comment or '}' (line 1, column 20 (offset: 19))
"create (n:node0{78 : 78})"
^
The book I am following "Learning Neo4j" by Bruggen, Packt Publishing.
My guess is that "78" cannot be a key name (most likely because it starts with a digit) and the correct code should be like
create (n:node0{param78: 78})
Related
I tried to merge a node with apoc.merge.node but my ident property keys have a special char(:) and get double escaped. Did i miss something or does a workaround exist?
If i replace the ":" with "_" everything works as expected.
Neo4j 4.2.1 community and APOC 4.2.0
CALL apoc.merge.node(["test"], apoc.map.fromPairs([["i:d","123"]])) YIELD node return node
Error
Failed to invoke procedure `apoc.merge.node`: Caused by: org.neo4j.exceptions.SyntaxException: Invalid input 'i': expected "}" (line 1, column 17 (offset: 16))
"MERGE (n:test{``i:d``:$identProps.``i:d``}) ON CREATE SET n += $onCreateProps ON MATCH SET n += $onMatchProps RETURN n"
EDIT
It seems there is a bug in APOC which causes the identifier to be encoded twice.
First with Util::quote https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/4.1/core/src/main/java/apoc/util/Util.java#L674
And then in the merge procedure https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/4.1/core/src/main/java/apoc/merge/Merge.java#L85
I've filed an issue: https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1783
In Neo4j, you can use backticks ` around a key that contain special characters :
CALL apoc.merge.node(["test"], apoc.map.fromPairs([["`i:d`","123"]]))
YIELD node
return node
Same is true everywhere in the Cypher syntax, escaping a label with a whitespace for eg :
MERGE (n:`Land Vehicle` {id: "land-rover-1"})
I have an array of for each row in a csv file as followed:
[['thxx'], ['too', 'late', 'now', 'dumbass'], ['you', '‘', 're', 'so', 'dumb', '?', '?'], ['thxxx'], ['i', '‘', 'd', 'be', 'fucked']]
When I try to pass this on to the lemmatizer like this:
from nltk.stem import WordNetLemmatizer
lemmatized_words = [WordNetLemmatizer.lemmatize(word) for word in tokened_text]
print(lemmatized_words)
I get the following error:
TypeError: lemmatize() missing 1 required positional argument: 'word'
Why is that?
As a side question: Do I need to do this before passing this for Vectorization? I am building an machine learning model and saw the function CountVectorizer in sci kit learn but could not find any information that it does lemmatization and so on beforehand as well.
There are some things wrong in your code:
WordNetLemmatizer is a class, you need to instanciate it first
tokened_text is a nested list, hence you need a nested list-comprehension to preserve the structure. Also lemmatize is expecting a string.
Here's how you could do this:
from nltk.stem import WordNetLemmatizer
wnl = WordNetLemmatizer()
lemmatized_words = [[wnl.lemmatize(word) for word in l] for l in tokened_text]
Traceback (most recent call last):
File "C:/Users/tarun/PycharmProjects/Yumnam_jr_ChatBot/training.py", line 31, in <module>
words = [lemmatizer.lemmatize(word) for word in words if word not in ignore_letter]
File "C:/Users/tarun/PycharmProjects/Yumnam_jr_ChatBot/training.py", line 31, in <listcomp>
words = [lemmatizer.lemmatize(word) for word in words if word not in ignore_letter]
TypeError: lemmatize() missing 1 required positional argument: 'word'
The error is "Parameter 'self' unfilled". So, what you need to do is install the "package 'self' Version 2020.12.3" and write like the following:-
lemmatizer = WordNetLemmatizer
words = [lemmatizer.lemmatize(self, word) for word in words if word not in ignore_letter]
words = sorted(set(words))
It works fine for me.
The reason of getting the error is you are missing () after the function name while assigning it to variable
xyz = WordNetLemmatizer() --> this bracket is missing leading to the error
You can just write this to make your code work
your_variable_here = WordNetLemmatizer()
In your code, you haven't added the parentheses () after the WordNetLemmatizer.
Add that and you are good to go.
This Cypher statement causes a syntax error:
CREATE (mediawiki-1.27:Schema { key: mediawiki-1.27, name:mediawiki-1.27})
The error seems to be caused by the - character in the node label:
Invalid input '1': expected whitespace, [ or '-' (line 1, column 19 (offset: 18))
"CREATE (mediawiki-1.27:Schema { key: mediawiki-1.27, name:mediawiki-1.27})"
Dashes and dots are not allowed in variable names. You can surround the variable name with backticks to escape it.
Also I'm guessing your key and name values are strings, in which case make sure to surround them with quotes:
CREATE (`mediawiki-1.27`:Schema { key:'mediawiki-1.27', name:'mediawiki-1.27'})
MATCH (p:Product {id:'19134046594'})-[r]-> (o:Attributes {4g:'network'}) return o
I received this exception:
Exception in thread "main" java.lang.RuntimeException: org.neo4j.driver.v1.exceptions.ClientException: Invalid input ':': expected an identifier character, whitespace or '}' (line 1, column 66 (offset: 65))
It's complaining about '4g'. Is '4g' an invalid property key identifier in neo4j? How to work around the issue?
You can use the backtick (`) character to quote property names that start with an otherwise illegal character.
For example, this would work:
CREATE (o:Attributes {`4g`: 'network'})
RETURN o;
And this also works:
MATCH (o:Attributes) WHERE o.`4g` = 'network'
RETURN o;
According to the naming rules section of the documentation, names you use (which does include property keys):
Must begin with an alphabetic letter.
and
Can contain numbers, but not as the first character.
You can however start it off with an underscore, so _4g:'network' would work.
I'm guessing this is just for example purposes, but it does seem to me that it would be better the other way around: network:'4g'.
PEG-based parser generators usually provide limited error reporting on invalid inputs. From what I read, the parse dialect of rebol is inspired by PEG grammars extended with regular expressions.
For example, typing the following in JavaScript:
d8> function () {}
gives the following error, because no identifier was provided in declaring a global function:
(d8):1: SyntaxError: Unexpected token (
function () {}
^
The parser is able to pinpoint exactly the position during parsing where an expected token is missing. The character position of the expected token is used to position the arrow in the error message.
Does the parse dialect in rebol provides built-in facilities to report the line and column errors on invalid inputs?
Otherwise, are there examples out there of custom rolled out parse rules that provide such error reporting?
I've done very advanced Rebol parsers which manage live and mission-critical TCP servers, and doing proper error reporting was a requirement. So this is important!
Probably one of the most unique aspects of Rebol's PARSE is that you can include direct evaluation within the rules. So you can set variables to track the parse position, or the error messages, etc. (It's very easy because the nature of Rebol is that mixing code and data as the same thing is a core idea.)
So here's the way I did it. Before each match rule is attempted, I save the parse position into "here" (by writing here:) and then also save an error into a variable using code execution (by putting (error: {some error string}) in parentheses so that the parse dialect runs it). If the match rule succeeds, we don't need to use the error or position...and we just go on to the next rule. But if it fails we will have the last state we set to report after the failure.
Thus the pattern in the parse dialect is simply:
; use PARSE dialect handling of "set-word!" instances to save parse
; position into variable named "here"
here:
; escape out of the parse dialect using parentheses, and into the DO
; dialect to run arbitrary code. Here we run code that saves an error
; message string into a variable named "error"
(error: "<some error message relating to rule that follows>")
; back into the PARSE dialect again, express whatever your rule is,
; and if it fails then we will have the above to use in error reporting
what: (ever your) [rule | {is}]
That's basically what you need to do. Here is an example for phone numbers:
digit: charset "012345689"
phone-number-rule: [
here:
(error: "invalid area code")
["514" | "800" | "888" | "916" "877"]
here:
(error: "expecting dash")
"-"
here:
(error: "expecting 3 digits")
3 digit
here:
(error: "expecting dash")
"-"
here:
(error: "expecting 4 digits")
4 digit
(error: none)
]
Then you can see it in action. Notice that we set error to none if we reach the end of the parse rules. PARSE will return false if there is still more input to process, so if we notice there is no error set but PARSE returns false anyway... we failed because there was too much extra input:
input: "800-22r2-3333"
if not parse input phone-number-rule [
if none? error [
error: "too much data for phone number"
]
]
either error [
column: length? copy/part input here newline
print rejoin ["error at position:" space column]
print error
print input
print rejoin [head insert/dup "" space column "^^"}
print newline
][
print {all good}
]
The above will print the following:
error at position: 4
expecting 3 digits
800-22r2-3333
^
Obviously, you could do much more potent stuff, since whatever you put in parens will be evaluated just like normal Rebol source code. It's really flexible. I even have parsers which update progress bars while loading huge datasets... :-)
Here is a simple example of finding the position during parsing a string which could be used to do what you ask.
Let us say that our code is only valid if it contains a and b characters, anything else would be illegal input.
code-rule: [
some [
"a" |
"b"
]
[ end | mark: (print [ "Failed at position" index? mark ]) ]
]
Let's check that with some valid code
>> parse "aaaabbabb" code-rule
== true
Now we can try again with some invalid input
>> parse "aaaabbXabb" code-rule
Failed at position 7
== false
This is a rather simplified example language, but it should be easy to extend to more a complex example.