Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-22-2020 03:27 AM
When loading a CSV like this
LOAD CSV FROM 'file:///sentence.csv' AS line
CREATE (:SENTENCE { name: line})
The nodes created will make name-arrays in rows with commas
{
"identity": 1,
"labels": [
"SENTENCE"
],
"properties": {
"name": [
"this is the sentence",
" which makes this weird problem",
" separating by the commas"
]
}
}
I want to just all rows as complete values, whatever symbols are in the CSV. Every line should be a node name
sample of csv:
Hvis du fik tilbudt 100.000 kr, men din værste fjende ville få 500.000 kr, ville du så stadigvæk tage imod tilbuddet?
Hvilke råd synes så indlysende korrekte og ligetil at efterfølge, men bliver altid ignoreret
Hvornår blev du første gang opmærksom på, hvad det vil sige at være dansk?
Fortæl om et sted i Danmark, der betyder noget særligt for dig. Hvor i Danmark føler du dig hjemme? Hvad savner du ved Danmark, når du har været væk?
Solved! Go to Solution.
09-24-2020 07:40 AM
I want to follow up on this.
I have an Excel-spreadsheet with sentences with both comma (,) and quotation marks (").
When choosing save as CSV in Excel, there are different types of CSV, some of them not even seperated with commas, but rather with semicolons or tabulator.
I choose the one that says "kommasepareret" (comma seperated), partly because it also allows for UTC-8 which is handy when using æøåé and other symbols.
The spreadsheet i am exporting as CSV does only have one column and therefore no fieldterminator
My solution was neither to put quotation marks around the lines, nor to escape the commas or quotation marks. instead in just filled the second column with the same word: "STINKYWINKY" and exported to CSV
This gave me this spreadsheet
and when opened in notepad it looks like this
Which, as you can see, added SEMICOLON as fieldterminator and then my magic word.
The i simply ran this query:
LOAD CSV FROM 'file:///emner.csv' AS line FIELDTERMINATOR ';'
CREATE (:SENTENCE { name: line[0]})
and then it worked.
09-22-2020 04:16 AM
You can add quotation marks to the lines in the CSV to tell it's full strings – otherwise the CSV interpreter will expect that it's comma separated values 🙂
In case you have quotation marks in any of the lines, you will need to escape them as per https://neo4j.com/docs/cypher-manual/current/clauses/load-csv/#csv-file-format
09-22-2020 02:42 PM
The "sample of csv" you provided is NOT a csv. That's why you're having trouble.
CSV means "Comma Separated Values".
What you have is a list of strings separated by newlines. There are ways to address this, as @Thomas_Silkjaer pointed out (wb Thomas! ). IMO, I'd just fix the source file, and make sure it was a CSV, or turn it into json, and use apoc.load.json.
sentence
"Hvis du fik tilbudt 100.000 kr, men din værste fjende ville få 500.000 kr, ville du så stadigvæk tage imod tilbuddet?"
"Hvilke råd synes så indlysende korrekte og ligetil at efterfølge, men bliver altid ignoreret"
"Hvornår blev du første gang opmærksom på, hvad det vil sige at være dansk?"
"Fortæl om et sted i Danmark, der betyder noget særligt for dig. Hvor i Danmark føler du dig hjemme? Hvad savner du ved Danmark, når du har været væk?"
[
"Hvis du fik tilbudt 100.000 kr, men din værste fjende ville få 500.000 kr, ville du så stadigvæk tage
imod tilbuddet?",
"Hvilke råd synes så indlysende korrekte og ligetil at efterfølge, men bliver altid ignoreret",
"Hvornår blev du første gang opmærksom på, hvad det vil sige at være dansk?",
"Fortæl om et sted i Danmark, der betyder noget særligt for dig. Hvor i Danmark føler du dig hjemme? Hvad savner du ved Danmark, når du har været væk?"
]
09-23-2020 02:11 PM
You can convert text file to csv using java. Check this link:
09-24-2020 07:40 AM
I want to follow up on this.
I have an Excel-spreadsheet with sentences with both comma (,) and quotation marks (").
When choosing save as CSV in Excel, there are different types of CSV, some of them not even seperated with commas, but rather with semicolons or tabulator.
I choose the one that says "kommasepareret" (comma seperated), partly because it also allows for UTC-8 which is handy when using æøåé and other symbols.
The spreadsheet i am exporting as CSV does only have one column and therefore no fieldterminator
My solution was neither to put quotation marks around the lines, nor to escape the commas or quotation marks. instead in just filled the second column with the same word: "STINKYWINKY" and exported to CSV
This gave me this spreadsheet
and when opened in notepad it looks like this
Which, as you can see, added SEMICOLON as fieldterminator and then my magic word.
The i simply ran this query:
LOAD CSV FROM 'file:///emner.csv' AS line FIELDTERMINATOR ';'
CREATE (:SENTENCE { name: line[0]})
and then it worked.
All the sessions of the conference are now available online