Cypher Query for Fork Pattern - PullRequest
       21

Cypher Query for Fork Pattern

0 голосов
/ 25 июня 2019

Я пытаюсь составить запрос на графике токенов-слов, со связями которых слово находится перед следующим словом. Я хочу запросить шаблон, который выглядит как график или Y на графике, с общей парой последовательных слов и двумя разными словами, следующими за парой. Например, на графике из Бытия 1 мне может потребоваться запросить пары разных слов после фразы «над каждым», за которыми может следовать «живой» или «ползучий».

Вместо того, чтобы возвращать все слова, следующие за фразой, было бы лучше, если бы оба разных слова были возвращены в одной и той же записи. Целью этого запроса было бы выявить неявные отношения между живыми и ползучими, как «родственные» слова, что было бы легче, если бы они возвращались вместе таким образом.

Моей первоначальной мыслью было бы просто сделать два совпадения в последовательности слов, следующих за фразой, и объединить их вместе, чтобы объединить разные слова. Но я надеялся, что может быть более прямой путь, о котором я просто не знаю. Это существует? enter image description here

Редактировать

Пример запроса, чтобы помочь понять идею:

MATCH
    (o {text: "OVER"})-[:BEFORE]->(e {text: "EVERY"})-[:BEFORE]->(t), 
    (o)-[:BEFORE]->(e)-[:BEFORE]->(c)
CREATE (l)-[:SIBLING]->(c)

Ответы [ 2 ]

0 голосов
/ 10 июля 2019

принятый ответ из Что делает запятая в запросе Cypher? была немного ближе, чем мой первоначальный подход.Это включало использование запятых для создания форка в шаблоне, поэтому вместо приведенного выше MATCH предложения

MATCH
    (o {text: "OVER"})-[:BEFORE]->(e {text: "EVERY"})-[:BEFORE]->(t), 
    (o)-[:BEFORE]->(e)-[:BEFORE]->(c)

я бы просто сделал

MATCH
    (o {text: "OVER"})-[:BEFORE]->(e {text: "EVERY"})-[:BEFORE]->(t), 
    (e)-[:BEFORE]->(c)

Нет необходимости повторного сопоставления (o)-[:BEFORE]->(e).

Использование второго предложения MATCH действительно дало мне образец форка, который я пытался сопоставить, однако в результатах отсутствовал соответствующий уровень контекста - вместо того, чтобы возвращать все слова, следующие за фразой «НАД КАЖДЫМ», он просто вернул все слова, следующие за «КАЖДЫМ».После дальнейших размышлений это имело смысл, поскольку именно это я и просил;сопоставьте «OVER», «EVERY» и любые два слова, следующие за «EVERY».Единственный контекст, который у меня был на графике, заключался в том, какое слово за каким;не было никакого контекста относительно того, какое слово следовало за какой фразой.

Чтобы исправить это, я закончил пересоздание своего графа, предоставив ему полный фразовый контекст.Исходная графовая модель просто имела узлы всех уникальных слов в документе, с отношениями которых одно уникальное слово было раньше другого - хорошие данные для простого двухугольного марковского дерева, плохие для длинных n-угольников.Новая графовая модель по-прежнему содержит набор узлов, представляющих уникальные слова документа, а также другой набор узлов, представляющих каждое отдельное слово.Отдельные слова связаны друг с другом в том порядке, в котором они появляются в документе, что в итоге выглядит как длинный ряд узлов слов.Уникальные слова связаны с точки зрения которых являются братьями и сестрами вилки с общей фразой длиной в три слова.С учетом правильного фразового контекста я смог получить родственные связи, которые искал изначально.

Код

Оригинальная модель

Уникальные узлы слова (пример):

CREATE (CommaChar:Token {text:','})
CREATE (PeriodChar:Token {text:'.'})
CREATE (ColonChar:Token {text:':'})
CREATE (SemicolonChar:Token {text:';'})
CREATE (A:Token {text:'A'})
CREATE (Above:Token {text:'ABOVE'})
CREATE (Abundantly:Token {text:'ABUNDANTLY'})
CREATE (After:Token {text:'AFTER'})
CREATE (Air:Token {text:'AIR'})
CREATE (All:Token {text:'ALL'})
CREATE (Also:Token {text:'ALSO'})
CREATE (And:Token {text:'AND'})
CREATE (Appear:Token {text:'APPEAR'})
CREATE (Be:Token {text:'BE'})
CREATE (Bearing:Token {text:'BEARING'})
...
CREATE (Whales:Token {text:'WHALES'})
CREATE (Wherein:Token {text:'WHEREIN'})
CREATE (Which:Token {text:'WHICH'})
CREATE (Whose:Token {text:'WHOSE'})
CREATE (Winged:Token {text:'WINGED'})
CREATE (Without:Token {text:'WITHOUT'})
CREATE (Years:Token {text:'YEARS'})
CREATE (Yielding:Token {text:'YIELDING'})
CREATE (You:Token {text:'YOU'})

BEFORE взаимосвязи:

CREATE (PhraseStart)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Beginning)-[:BEFORE]->(God)-[:BEFORE]->(Created)-[:BEFORE]->(The)-[:BEFORE]->(Heaven)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(Was)-[:BEFORE]->(Without)-[:BEFORE]->(Form)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Void)-[:BEFORE]->(SemicolonChar)-[:BEFORE]->(And)-[:BEFORE]->(Darkness)-[:BEFORE]->(Was)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Face)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Deep)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Spirit)-[:BEFORE]->(Of)-[:BEFORE]->(God)-[:BEFORE]->(Moved)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Face)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(There)-[:BEFORE]->(Be)-[:BEFORE]->(Light)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(There)-[:BEFORE]->(Was)-[:BEFORE]->(Light)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(The)-[:BEFORE]->(Light)-[:BEFORE]->(CommaChar)-[:BEFORE]->(That)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Good)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Divided)-[:BEFORE]->(The)-[:BEFORE]->(Light)-[:BEFORE]->(From)-[:BEFORE]->(The)-[:BEFORE]->(Darkness)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Called)-[:BEFORE]->(The)-[:BEFORE]->(Light)-[:BEFORE]->(Day)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Darkness)-[:BEFORE]->(He)-[:BEFORE]->(Called)-[:BEFORE]->(Night)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Evening)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Morning)-[:BEFORE]->(Were)-[:BEFORE]->(The)-[:BEFORE]->(First)-[:BEFORE]->(Day)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(There)-[:BEFORE]->(Be)-[:BEFORE]->(A)-[:BEFORE]->(Firmament)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Midst)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Let)-[:BEFORE]->(It)-[:BEFORE]->(Divide)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(From)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Made)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Divided)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(Which)-[:BEFORE]->(Were)-[:BEFORE]->(Under)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(From)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(Which)-[:BEFORE]->(Were)-[:BEFORE]->(Above)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(So)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Called)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(Heaven)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Evening)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Morning)-[:BEFORE]->(Were)-[:BEFORE]->(The)-[:BEFORE]->(Second)-[:BEFORE]->(Day)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(Under)-[:BEFORE]->(The)-[:BEFORE]->(Heaven)-[:BEFORE]->(Be)-[:BEFORE]->(Gathered)-[:BEFORE]->(Together)-[:BEFORE]->(Unto)-[:BEFORE]->(One)-[:BEFORE]->(Place)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Let)-[:BEFORE]->(The)-[:BEFORE]->(Dry)-[:BEFORE]->(Land)-[:BEFORE]->(Appear)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(So)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Called)-[:BEFORE]->(The)-[:BEFORE]->(Dry)-[:BEFORE]->(Land)-[:BEFORE]->(Earth)-[:BEFORE]->(SemicolonChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Gathering)-[:BEFORE]->(Together)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(Called)-[:BEFORE]->(He)-[:BEFORE]->(Seas)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(That)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Good)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(Bring)-[:BEFORE]->(Forth)-[:BEFORE]->(Grass)-[:BEFORE]->(CommaChar)-[:BEFORE]->(The)-[:BEFORE]->(Herb)-[:BEFORE]->(Yielding)-[:BEFORE]->(Seed)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Fruit)-[:BEFORE]->(Tree)-[:BEFORE]->(Yielding)-[:BEFORE]->(Fruit)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Whose)-[:BEFORE]->(Seed)-[:BEFORE]->(Is)-[:BEFORE]->(In)-[:BEFORE]->(Itself)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(So)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(Brought)-[:BEFORE]->(Forth)-[:BEFORE]->(Grass)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Herb)-[:BEFORE]->(Yielding)-[:BEFORE]->(Seed)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Tree)-[:BEFORE]->(Yielding)-[:BEFORE]->(Fruit)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Whose)-[:BEFORE]->(Seed)-[:BEFORE]->(Was)-[:BEFORE]->(In)-[:BEFORE]->(Itself)-[:BEFORE]->(CommaChar)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(That)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Good)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Evening)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Morning)-[:BEFORE]->(Were)-[:BEFORE]->(The)-[:BEFORE]->(Third)-[:BEFORE]->(Day)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(There)-[:BEFORE]->(Be)-[:BEFORE]->(Lights)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Heaven)-[:BEFORE]->(To)-[:BEFORE]->(Divide)-[:BEFORE]->(The)-[:BEFORE]->(Day)-[:BEFORE]->(From)-[:BEFORE]->(The)-[:BEFORE]->(Night)-[:BEFORE]->(SemicolonChar)-[:BEFORE]->(And)-[:BEFORE]->(Let)-[:BEFORE]->(Them)-[:BEFORE]->(Be)-[:BEFORE]->(For)-[:BEFORE]->(Signs)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(For)-[:BEFORE]->(Seasons)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(For)-[:BEFORE]->(Days)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Years)-[:BEFORE]->(ColonChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(Let)-[:BEFORE]->(Them)-[:BEFORE]->(Be)-[:BEFORE]->(For)-[:BEFORE]->(Lights)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Heaven)-[:BEFORE]->(To)-[:BEFORE]->(Give)-[:BEFORE]->(Light)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(So)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Made)-[:BEFORE]->(Two)-[:BEFORE]->(Great)-[:BEFORE]->(Lights)-[:BEFORE]->(SemicolonChar)-[:BEFORE]->(The)-[:BEFORE]->(Greater)-[:BEFORE]->(Light)-[:BEFORE]->(To)-[:BEFORE]->(Rule)-[:BEFORE]->(The)-[:BEFORE]->(Day)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Lesser)-[:BEFORE]->(Light)-[:BEFORE]->(To)-[:BEFORE]->(Rule)-[:BEFORE]->(The)-[:BEFORE]->(Night)-[:BEFORE]->(ColonChar)-[:BEFORE]->(He)-[:BEFORE]->(Made)-[:BEFORE]->(The)-[:BEFORE]->(Stars)-[:BEFORE]->(Also)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Set)-[:BEFORE]->(Them)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Firmament)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Heaven)-[:BEFORE]->(To)-[:BEFORE]->(Give)-[:BEFORE]->(Light)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(To)-[:BEFORE]->(Rule)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Day)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Night)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(To)-[:BEFORE]->(Divide)-[:BEFORE]->(The)-[:BEFORE]->(Light)-[:BEFORE]->(From)-[:BEFORE]->(The)-[:BEFORE]->(Darkness)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(That)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Good)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Evening)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Morning)-[:BEFORE]->(Were)-[:BEFORE]->(The)-[:BEFORE]->(Fourth)-[:BEFORE]->(Day)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(Bring)-[:BEFORE]->(Forth)-[:BEFORE]->(Abundantly)-[:BEFORE]->(The)-[:BEFORE]->(Moving)-[:BEFORE]->(Creature)-[:BEFORE]->(That)-[:BEFORE]->(Hath)-[:BEFORE]->(Life)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Fowl)-[:BEFORE]->(That)-[:BEFORE]->(May)-[:BEFORE]->(Fly)-[:BEFORE]->(Above)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Open)-[:BEFORE]->(Firmament)-[:BEFORE]->(Of)-[:BEFORE]->(Heaven)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Created)-[:BEFORE]->(Great)-[:BEFORE]->(Whales)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Every)-[:BEFORE]->(Living)-[:BEFORE]->(Creature)-[:BEFORE]->(That)-[:BEFORE]->(Moveth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Which)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(Brought)-[:BEFORE]->(Forth)-[:BEFORE]->(Abundantly)-[:BEFORE]->(CommaChar)-[:BEFORE]->(After)-[:BEFORE]->(Their)-[:BEFORE]->(Kind)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Every)-[:BEFORE]->(Winged)-[:BEFORE]->(Fowl)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(That)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Good)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Blessed)-[:BEFORE]->(Them)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Saying)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Be)-[:BEFORE]->(Fruitful)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Multiply)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Fill)-[:BEFORE]->(The)-[:BEFORE]->(Waters)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Seas)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Let)-[:BEFORE]->(Fowl)-[:BEFORE]->(Multiply)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Evening)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Morning)-[:BEFORE]->(Were)-[:BEFORE]->(The)-[:BEFORE]->(Fifth)-[:BEFORE]->(Day)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(Bring)-[:BEFORE]->(Forth)-[:BEFORE]->(The)-[:BEFORE]->(Living)-[:BEFORE]->(Creature)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Cattle)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Creeping)-[:BEFORE]->(Thing)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Beast)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(So)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Made)-[:BEFORE]->(The)-[:BEFORE]->(Beast)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Cattle)-[:BEFORE]->(After)-[:BEFORE]->(Their)-[:BEFORE]->(Kind)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Every)-[:BEFORE]->(Thing)-[:BEFORE]->(That)-[:BEFORE]->(Creepeth)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(After)-[:BEFORE]->(His)-[:BEFORE]->(Kind)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(That)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Good)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Let)-[:BEFORE]->(Us)-[:BEFORE]->(Make)-[:BEFORE]->(Man)-[:BEFORE]->(In)-[:BEFORE]->(Our)-[:BEFORE]->(Image)-[:BEFORE]->(CommaChar)-[:BEFORE]->(After)-[:BEFORE]->(Our)-[:BEFORE]->(Likeness)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(Let)-[:BEFORE]->(Them)-[:BEFORE]->(Have)-[:BEFORE]->(Dominion)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Fish)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Sea)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Fowl)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Air)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Cattle)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(All)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(Every)-[:BEFORE]->(Creeping)-[:BEFORE]->(Thing)-[:BEFORE]->(That)-[:BEFORE]->(Creepeth)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(So)-[:BEFORE]->(God)-[:BEFORE]->(Created)-[:BEFORE]->(Man)-[:BEFORE]->(In)-[:BEFORE]->(His)-[:BEFORE]->(Own)-[:BEFORE]->(Image)-[:BEFORE]->(CommaChar)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Image)-[:BEFORE]->(Of)-[:BEFORE]->(God)-[:BEFORE]->(Created)-[:BEFORE]->(He)-[:BEFORE]->(Him)-[:BEFORE]->(SemicolonChar)-[:BEFORE]->(Male)-[:BEFORE]->(And)-[:BEFORE]->(Female)-[:BEFORE]->(Created)-[:BEFORE]->(He)-[:BEFORE]->(Them)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Blessed)-[:BEFORE]->(Them)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(Unto)-[:BEFORE]->(Them)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Be)-[:BEFORE]->(Fruitful)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Multiply)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Replenish)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Subdue)-[:BEFORE]->(It)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(Have)-[:BEFORE]->(Dominion)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Fish)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Sea)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(The)-[:BEFORE]->(Fowl)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Air)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Over)-[:BEFORE]->(Every)-[:BEFORE]->(Living)-[:BEFORE]->(Thing)-[:BEFORE]->(That)-[:BEFORE]->(Moveth)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Said)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Behold)-[:BEFORE]->(CommaChar)-[:BEFORE]->(I)-[:BEFORE]->(Have)-[:BEFORE]->(Given)-[:BEFORE]->(You)-[:BEFORE]->(Every)-[:BEFORE]->(Herb)-[:BEFORE]->(Bearing)-[:BEFORE]->(Seed)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Which)-[:BEFORE]->(Is)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Face)-[:BEFORE]->(Of)-[:BEFORE]->(All)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(Every)-[:BEFORE]->(Tree)-[:BEFORE]->(CommaChar)-[:BEFORE]->(In)-[:BEFORE]->(The)-[:BEFORE]->(Which)-[:BEFORE]->(Is)-[:BEFORE]->(The)-[:BEFORE]->(Fruit)-[:BEFORE]->(Of)-[:BEFORE]->(A)-[:BEFORE]->(Tree)-[:BEFORE]->(Yielding)-[:BEFORE]->(Seed)-[:BEFORE]->(SemicolonChar)-[:BEFORE]->(To)-[:BEFORE]->(You)-[:BEFORE]->(It)-[:BEFORE]->(Shall)-[:BEFORE]->(Be)-[:BEFORE]->(For)-[:BEFORE]->(Meat)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(To)-[:BEFORE]->(Every)-[:BEFORE]->(Beast)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(To)-[:BEFORE]->(Every)-[:BEFORE]->(Fowl)-[:BEFORE]->(Of)-[:BEFORE]->(The)-[:BEFORE]->(Air)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(To)-[:BEFORE]->(Every)-[:BEFORE]->(Thing)-[:BEFORE]->(That)-[:BEFORE]->(Creepeth)-[:BEFORE]->(Upon)-[:BEFORE]->(The)-[:BEFORE]->(Earth)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Wherein)-[:BEFORE]->(There)-[:BEFORE]->(Is)-[:BEFORE]->(Life)-[:BEFORE]->(CommaChar)-[:BEFORE]->(I)-[:BEFORE]->(Have)-[:BEFORE]->(Given)-[:BEFORE]->(Every)-[:BEFORE]->(Green)-[:BEFORE]->(Herb)-[:BEFORE]->(For)-[:BEFORE]->(Meat)-[:BEFORE]->(ColonChar)-[:BEFORE]->(And)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(So)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)
CREATE (PhraseStart)-[:BEFORE]->(And)-[:BEFORE]->(God)-[:BEFORE]->(Saw)-[:BEFORE]->(Every)-[:BEFORE]->(Thing)-[:BEFORE]->(That)-[:BEFORE]->(He)-[:BEFORE]->(Had)-[:BEFORE]->(Made)-[:BEFORE]->(CommaChar)-[:BEFORE]->(And)-[:BEFORE]->(CommaChar)-[:BEFORE]->(Behold)-[:BEFORE]->(CommaChar)-[:BEFORE]->(It)-[:BEFORE]->(Was)-[:BEFORE]->(Very)-[:BEFORE]->(Good)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Evening)-[:BEFORE]->(And)-[:BEFORE]->(The)-[:BEFORE]->(Morning)-[:BEFORE]->(Were)-[:BEFORE]->(The)-[:BEFORE]->(Sixth)-[:BEFORE]->(Day)-[:BEFORE]->(PeriodChar)-[:BEFORE]->(PhraseEnd)

Запрос к брату:

MATCH
    (a:Token)-[:BEFORE]->(b:Token)-[:BEFORE]-(c:Token),
    (b)-[:BEFORE]->(d:Token)
RETURN c, d

Возвращает все пары токенов с обоими токенами в паре после токена b.

Текущая модель

Узлы уникальных слов (должны быть сделаны братья и сестры):

CREATE (CommaChar:SibToken {text:','})
CREATE (PeriodChar:SibToken {text:'.'})
CREATE (ColonChar:SibToken {text:':'})
CREATE (SemicolonChar:SibToken {text:';'})
CREATE (A:SibToken {text:'A'})
CREATE (Above:SibToken {text:'ABOVE'})
CREATE (Abundantly:SibToken {text:'ABUNDANTLY'})
CREATE (After:SibToken {text:'AFTER'})
CREATE (Air:SibToken {text:'AIR'})
CREATE (All:SibToken {text:'ALL'})
CREATE (Also:SibToken {text:'ALSO'})
CREATE (And:SibToken {text:'AND'})
CREATE (Appear:SibToken {text:'APPEAR'})
CREATE (Be:SibToken {text:'BE'})
CREATE (Bearing:SibToken {text:'BEARING'})
...
CREATE (Whales:SibToken {text:'WHALES'})
CREATE (Wherein:SibToken {text:'WHEREIN'})
CREATE (Which:SibToken {text:'WHICH'})
CREATE (Whose:SibToken {text:'WHOSE'})
CREATE (Winged:SibToken {text:'WINGED'})
CREATE (Without:SibToken {text:'WITHOUT'})
CREATE (Years:SibToken {text:'YEARS'})
CREATE (Yielding:SibToken {text:'YIELDING'})
CREATE (You:SibToken {text:'YOU'})

Подключены отдельные слова (пример):

CREATE (In0:Token {text: "IN", id: 0})-[:BEFORE]->(The1:Token {text: "THE", id: 1})-[:BEFORE]->(Beginning2:Token {text: "BEGINNING", id: 2})-[:BEFORE]->(God3:Token {text: "GOD", id: 3})-[:BEFORE]->(Created4:Token {text: "CREATED", id: 4})-[:BEFORE]->(The5:Token {text: "THE", id: 5})-[:BEFORE]->(Heaven6:Token {text: "HEAVEN", id: 6})-[:BEFORE]->(And7:Token {text: "AND", id: 7})-[:BEFORE]->(The8:Token {text: "THE", id: 8})-[:BEFORE]->(Earth9:Token {text: "EARTH", id: 9})-[:BEFORE]->(PeriodChar10:Token {text: ".", id: 10})-[:BEFORE]->(And11:Token {text: "AND", id: 11})...(And910:Token {text: "AND", id: 910})-[:BEFORE]->(The911:Token {text: "THE", id: 911})-[:BEFORE]->(Evening912:Token {text: "EVENING", id: 912})-[:BEFORE]->(And913:Token {text: "AND", id: 913})-[:BEFORE]->(The914:Token {text: "THE", id: 914})-[:BEFORE]->(Morning915:Token {text: "MORNING", id: 915})-[:BEFORE]->(Were916:Token {text: "WERE", id: 916})-[:BEFORE]->(The917:Token {text: "THE", id: 917})-[:BEFORE]->(Sixth918:Token {text: "SIXTH", id: 918})-[:BEFORE]->(Day919:Token {text: "DAY", id: 919})-[:BEFORE]->(PeriodChar920:Token {text: ".", id: 920})

Запрос одного брата:

MATCH (a1:Token)-[:BEFORE]->(b1:Token)-[:BEFORE]->(c1:Token)-[:BEFORE]->(d1:Token)
MATCH (a2:Token)-[:BEFORE]->(b2:Token)-[:BEFORE]->(c2:Token)-[:BEFORE]->(d2:Token)
MATCH (s1:SibToken)
MATCH (s2:SibToken)
WHERE a1.text = a2.text AND b1.text = b2.text AND c1.text = c2.text AND d1.text < d2.text AND s1.text = d1.text AND s2.text = d2.text
CREATE (s1)-[:SIBLING]->(s2)

График результатов запроса:

Full Sibling Graph

Особенно интересные клики:

Verb Cluster

Days and Nouns Clusters

0 голосов
/ 25 июня 2019

А как насчет наборов слов?

Я добавлю метки сюда, используя: Word на данный момент (вы должны использовать метки и индексы, если это возможно)

MATCH
    (o:Word {text: "OVER"})-[:BEFORE]->(e:Word {text: "EVERY"})-[:BEFORE]->(next)
RETURN collect(next.text) as nextWords
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...