cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Problem with property list

Hi,
i'am new in neo4j, and i have a problem. I have two nodes type, Authors and Articles.
Authors' property are(name, surname, ScopusId), and Articles' property are (title, source,idScopusArticle,AuthorsId). AuthorsId is a list, and it contains the authors' idScopus that had wrote the article. How can i create a label (authors)-[:publicate]->(Articles) for all authors in the list ?
please help me

8 REPLIES 8

Hi,

If AuthorsIds is a list, you need to UNWIND it to get each id individually. Then you can get the corresponding Author node, and create the relationship from there.

MATCH (article:Article)
UNWIND article.AuthorsIds as authorId
WITH article, authorId
MATCH (author:Author {id: authorId})
CREATE (author)-[:PUBLICATE]->(article)

If for some reason, AuthorsIds is a string, you can transform it to a list with split

thank you for your help.
i try it, but match only with the first element's list.

I created a sample scenario:

MERGE (a:Authors {ScopusID: 'SID1'})
MERGE (a1:Authors {ScopusID: 'SID2'})
MERGE (a2:Authors {ScopusID: 'SID3'})

MERGE (b:Articles {title: 'Title1', idScopusArticle: 'A1', AuthorsId: ['SID1', 'SID2']})

Return a, a1, a2, b;
Result:
2X_5_5e3223e7c8bcc3d5eb16cf0e6024caa41153acd6.png

Select authors that match:

MATCH (b:Articles)
MATCH (a:Authors) WHERE a.ScopusID IN b.AuthorsId
Return a, b
Result:
2X_7_77a4262f39fb8c6f089b0d40cd2291a285e4405b.png

Create a relationship between matched authors and articles:
MATCH (b:Articles)
MATCH (a:Authors) WHERE a.ScopusID IN b.AuthorsId
MERGE (a)-[:PUBLICATE]->(b)
Return a, b
Result:
2X_c_cae43d7dd6df57aea88fa8d50196435ddca8b540.png

i try, but it doesn't works.
this is code for the nodes Authors and Articles
the code matchs only with the first element of the list

Authors:
load csv with headers from 'file:///Authors.csv' as line
merge(n:Authors{idScopus:line.idScopus,lastName:line.LastName,Name:line.FirstName,email:line.email,numberDoc:line.nDoc,numberCitiations:line.nCitations,nuberDocCitiation:line.nDocCitation,subjectArea:split(line.subjarea,",")})

Articles:
load csv with headers from 'file:///Scopus_article.csv' as line
create(n:Article{Authors:line.Authors,IdAuthors:split(line.AuthorsID,";"),Source:line.SourceTitle,title:line.Title,Year:toInteger(line.Year),Volume:toInteger(line.Volume),pageStart:line.PageStart,pageEnd:line.PageEnd,numberPage:line.PageCount,CitedBy:line.CitedBy,scopusID:line.EID})

In Articles i use CREATE because there are some "null" value in the csv.

Please send me one line from your Scopus_article.csv or at lease the value in column line.AuthorsID so that I can offer better solution.

Authors,AuthorsID,Title,Year,SourceTitle,Volume,Issue,ArtNo,PageStart,PageEnd,PageCount,CitedBy,DOI,Link,DocumentType,PublicationStage,AccessType,Source,EID
"Bianco, S., Buzzelli, M., Ciocca, G., Schettini, R.",55511749108; 55744003800; 6603733325; 56235309600,Neural architecture search for image saliency fusion,2020,Information Fusion,57,,,89,101,,,10.1016/j.inffus.2019.12.007,https://www.scopus.com/inward/record.url?eid=2-s2.0-85076853749&partnerID=40&md5=c8e29ac5494986cf3cf...

This IdAuthors:split(line.AuthorsID,";") stores the property value as an array. Here you need to use UNWIND to get all the author ids.

I created a scenario with your line.AuthorsID.

MERGE (a:Author {ScopusID: '55744003800'})
MERGE (a1:Author {ScopusID: ' 56235309600'})
MERGE (a2:Author {ScopusID: '55511749108'})
MERGE (a3:Author {ScopusID: ' 6603733325'})

MERGE (b:Article {title: 'TitleA', idScopusArticle: 'AA2', AuthorsId: split('55511749108; 55744003800; 6603733325', ';')})
MERGE (b1:Article {title: 'TitleB', idScopusArticle: 'AA3', AuthorsId: split('55744003800; 56235309600', ';')})

Select Article with a particular title, get all the matching authors and create the [:PUBLICATE] relationship between articles and authors. Here are the Cypher queries.

MATCH (b:Article)
WHERE b.title = "TitleA"
WITH b.AuthorsId as Authr, b
UNWIND Authr as Authrs
MATCH (a:Author) WHERE trim(a.ScopusID) = trim(Authrs)
MERGE (a)-[:PUBLICATE]->(b)
Return a, b
Resault:2X_9_9bdda81b67ddb651681887dfb38428a0b2e20d1e.png

MATCH (b:Article)
WHERE b.title = "TitleB"
WITH b.AuthorsId as Authr, b
UNWIND Authr as Authrs
MATCH (a:Author) WHERE trim(a.ScopusID) = trim(Authrs)
MERGE (a)-[:PUBLICATE]->(b)
Return a, b
Result:
2X_3_35d1c759c6c58b03bf795c9e0ebf94ea11fae092.png

thank you verry much ! it works !
is there a way to make it with all elements with one query ?