====== Lenga viva ligasons entre los mots ====== ===== Escript per crear una relacion ponderada entre los mots ===== WITH split(tolower(), ' ') AS words WITH [w in words WHERE NOT w IN ["the", "and", "i", "to"]] AS text UNWIND range(0, size(text)-2) AS i MERGE (w1:Word {name: text[i]}) MERGE (w2:Word {name: text[i+1]}) MERGE (w1)-[r:NEXT]->(w2) ON CREATE SET r.count =1 ON MATCH SET r.count = r.count + 1; ===== Requèsta per sortir los mots voids (stopwords) de la tièra ===== MATCH (p)-[:HAS_CATEGORY]-> (:Category{name:'lo temps que passa'}) WITH split(tolower(p.name), " ") AS words WITH [w IN words WHERE NOT w IN ["de","a","lo","la","un","una"]] AS text RETURN text; MATCH (s:Stopword) return COLLECT(s.word) MATCH (s:Stopword) WITH COLLECT(s.word) AS stopwords RETURN stopwords MATCH (s:Stopword) WITH COLLECT(s.word) AS stopwords MATCH (p)-[:HAS_CATEGORY]-> (:Category{name:'lo temps que passa'}) WITH split(tolower(p.name), " ") AS words, stopwords WITH [w IN words WHERE NOT w IN stopwords] AS text RETURN text; MATCH (s:Stopword) WITH collect(s.word) AS stopwords MATCH (p:Phrase) WITH split(tolower(p.name)," ") AS phrase,stopwords WITH [w IN phrase WHERE NOT w IN stopwords] AS text UNWIND range(0, size(text)-2) AS i MERGE (w1:Word{name: text[i]}) MERGE (w2:Word{name: text[i+1]}) MERGE (w1)-[r:NEXT]->(w2) ON CREATE SET r.count = 1 ON MATCH SET r.count = r.count + 1; ===== L'escript entièr ===== /** filename : relateCantalausaWords.cql Make sure the CONSTRAINT is created for the performance reasons */ CREATE CONSTRAINT ON (w:Word) ASSERT w.word IS UNIQUE; /** Destroy Word and :NEXT relationship */ MATCH (w:Word) DETACH DELETE w; /** Build the word nodes and the :NEXT relationship */ MATCH (p:Phrase) WITH REPLACE(p.name, '(', "") AS phrase WITH REPLACE(phrase, ')', "") AS phrase WITH REPLACE(phrase, ',', "") AS phrase WITH REPLACE(phrase, '.', "") AS phrase WITH REPLACE(phrase, '!', "") AS phrase WITH split(tolower(phrase)," ") AS words MATCH (s:Stopword) WITH collect(s.word) AS stopwords, words WITH [w IN words WHERE NOT w IN stopwords] AS text UNWIND range(0, size(text)-2) AS i MERGE (w1:Word{name: text[i]}) MERGE (w2:Word{name: text[i+1]}) MERGE (w1)-[r:NEXT]->(w2) ON CREATE SET r.count = 1 ON MATCH SET r.count = r.count + 1;