Conditional statement with string list

Hi,

In my following code, it is creating Node nodes whichever link is getting BUT I want to create/merge Category nodes if the link[''] value starts with 'Category:' and Node type nodes should be created if link[''] value doesn't start with 'Category:'.

P.S. In this Wikipedia API there is JSON field named as asterisk(*) by default, so don't get confuse with it.

CALL {
MATCH (n:Node { traversed:false })
RETURN n
LIMIT 5
}
CALL apoc.load.json('https://en.wikipedia.org/w/api.php?format=json&action=parse&prop=links&page=' + apoc.text.urlencode(n.name))
YIELD value as result
UNWIND result.parse.links AS link
MERGE (cn:Node {name: link['*']})
ON CREATE SET cn.traversed = false
MERGE (n)-[:Linked]->(cn)
SET n.traversed = true
RETURN 'Total nodes get: ' + count(result)

I have tried several WHERE and FOREACH clauses but these are not working with List type. Please let me know how to do it?

Thanks,
Mustafa

Take a look at your options here:

1 Like

Hi, You could use an APOC

CALL apoc.do.when(Predicate, SENTENCE) YIELD value

Thanks

1 Like

Thanks @andrew.bowman, apoc.do.when() worked for me Thanks :slight_smile:

Thanks @jggomez , it worked for me Thanks :slight_smile:

1 Like