Pular para o conteúdo principal

OpenCypher x Query using Context Meta-information (Edges Properties)

Testes no SandBox do Neo4J

MATCH (n) DETACH DELETE n;

CREATE (c1:Country { name: 'Germany', language: 'German', continent: 'Europe', population: 83000000 });
CREATE (c2:Country { name: 'France', language: 'French', continent: 'Europe', population: 67000000 });
CREATE (c3:Country { name: 'United Kingdom', language: 'English', continent: 'Europe', population: 66000000 });

MATCH (c1),(c2)
WHERE c1.name= 'Germany' AND c2.name = 'France'
CREATE (c2)<-[:WORKING_IN { date_of_start: 2014 }]-(p:Person { name: 'John' })-[:LIVING_IN { date_of_start: 2014 }]->(c1);

MATCH (c)
WHERE c.name= 'United Kingdom'
CREATE (c)<-[:WORKING_IN { date_of_start: 2014 }]-(p:Person { name: 'Harry' })-[:LIVING_IN { date_of_start: 2013 }]->(c);

MATCH (p1),(p2)
WHERE p1.name = 'John' AND p2.name = 'Harry'
CREATE (p1)-[:FRIENDS_WITH { date_of_start: 2011 }]->(p2);

MATCH (p1),(p2)
WHERE p1.name = 'John' AND p2.name = 'Harry'
CREATE (p1)<-[:FRIENDS_WITH { date_of_start: 2012 }]-(:Person { name: 'Anna' })-[:FRIENDS_WITH { date_of_start: 2014 }]->(p2);

MATCH (p),(c1),(c2)
WHERE p.name = 'Anna' AND c1.name = 'United Kingdom' AND c2.name = 'Germany'
CREATE (c2)<-[:LIVING_IN { date_of_start: 2016 }]-(p)-[:LIVING_IN { date_of_start: 2014 }]->(c1);

--

MATCH (n)-[r]->(m) RETURN n,r,m;

--

MATCH (:Country {name: 'United Kingdom'})-[r]-(p)
WHERE r.date_of_start = 2014
RETURN p;

--

MATCH (n:Person)-[k:FRIENDS_WITH]-(f)
WHERE k.date_of_start > 2010
RETURN n.name, f.name, k.date_of_start AS since

--

MATCH (n:Person)-[k1:FRIENDS_WITH]->(f1)
MATCH (n:Person)-[k2:FRIENDS_WITH]->(f2)
WHERE k2.date_of_start > k1.date_of_start
RETURN n.name, f2.name, k2.date_of_start AS since

--

MATCH (n1:Person)-[k1:FRIENDS_WITH]->(n3:Person)
MATCH (n2:Person)-[k2:FRIENDS_WITH]->(n4:Person)
WHERE k2.date_of_start = k1.date_of_start and n1 <> n2
RETURN n1.name, n3.name, n2.name, n4.name, k2.date_of_start AS since

--

MATCH (n1:Person)-[l1:LIVING_IN]->(c1:Country)
MATCH (n2:Person)-[l2:LIVING_IN]->(c2:Country)
WHERE l1.date_of_start = l2.date_of_start  and n1 <> n2
RETURN n1.name, c1.name, n2.name, c2.name, l2.date_of_start AS since

--

WITH 2010 AS since
MATCH rels= (p1:Person) - [:FRIENDS_WITH*1..2]->(p2:Person)
WHERE ALL(k1 in relationships(rels) WHERE k1.date_of_start > since)
RETURN rels;

Documentação

OpenCypher

MATCH, which searches for patterns, specify the patterns to search for in the database.;
OPTIONAL MATCH, specify the patterns to search for in the database while using nulls for missing parts of the pattern.
WHERE, for filtering the matched data;
RETURN, for defining what will be presented to the user in the result set;


WHERE is part of the directly preceding MATCH or OPTIONAL MATCH clause and should always be used like that to avoid problems with performance or results.

WHERE adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filters the results of a WITH clause.

WHERE EXISTS { ... } an existential sub-query used to filter the results of a MATCH, OPTIONAL MATCH or WITH clause.

Neo4j will just traverse all relationships and read the property value. There are by default no indexes on relationships properties (this can be achieved with the legacy indexes : check documentation).

RETURN ... [AS] projecting clauses: these comprise clauses that define which expressions to return in the result set. The returned expressions may all be aliased using AS.

Comentários

Postagens mais visitadas deste blog

Aprendizado de Máquina Relacional

 Extraído de -> https://www.lncc.br/~ziviani/papers/Texto-MC1-SBBD2019.pdf   Aprendizado de máquina relacional (AMR) destina-se à criação de modelos estatísticos para dados relacionais (seria o mesmo que dados conectados) , isto é, dados cuja a informação relacional é tão ou mais impor tante que a informação individual (atributos) de cada elemento.    Essa classe de aprendizado tem sido utilizada em diversas aplicações, por exemplo, na extração de informação de dados não estruturados [Zhang et al. 2016] e na modelagem de linguagem natural [Vu et al. 2018].   A adoção de técnicas de aprendizado de máquina relacional em tarefas de comple mentação de grafo de conhecimento se baseia na premissa de existência de regularidades semânticas presentes no mesmo . Modelos grafos probabilísticos  Baseada em regras / heurísticas que não podem garantir 100% de precisão no resultado da inferência mas os resultados podem ser explicados. Modelos de características de ...

Connected Papers: Uma abordagem alternativa para revisão da literatura

Durante um projeto de pesquisa podemos encontrar um artigo que nos identificamos em termos de problema de pesquisa e também de solução. Então surge a vontade de saber como essa área de pesquisa se desenvolveu até chegar a esse ponto ou quais desdobramentos ocorreram a partir dessa solução proposta para identificar o estado da arte nesse tema. Podemos seguir duas abordagens:  realizar uma revisão sistemática usando palavras chaves que melhor caracterizam o tema em bibliotecas digitais de referência para encontrar artigos relacionados ou realizar snowballing ancorado nesse artigo que identificamos previamente, explorando os artigos citados (backward) ou os artigos que o citam (forward)  Mas a ferramenta Connected Papers propõe uma abordagem alternativa para essa busca. O problema inicial é dado um artigo de interesse, precisamos encontrar outros artigos relacionados de "certa forma". Find different methods and approaches to the same subject Track down the state of the art rese...

Knowledge graphs: Introduction, history, and perspectives - Leitura de Artigo

Chaudhri, V. K., C. Baru, N. Chittar, X. L. Dong, M. Genesereth, J. Hendler, A. Kalyanpur, D. Lenat, J. Sequeda, D. Vrandečić, and K.Wang 2022. “ Knowledge graphs: Introduction, history, and perspectives. ” AI Magazine 43: 17–29. https://doi.org/10.1002/aaai.12033 Knowledge graphs (KGs) have emerged as a compelling abstraction for organizing the world’s structured knowledge and for integrating information extracted from multiple data sources. KNOWLEDGE GRAPH DEFINITION A KG is a directed labeled graph in which domain-specific meanings are associated with nodes and edges. [ Definição focado no COMO representar, diferente dos KBs ] There are multiple approaches for associating meanings with the nodes and edges. At the simplest level, the meanings could be stated as documentation strings expressed in a human understandable language such as English. At a computational level, the meanings can be expressed in a formal specification language such as first-order logic. An active area of curren...