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

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...

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 ...

KnOD 2021

Beyond Facts: Online Discourse and Knowledge Graphs A preface to the proceedings of the 1st International Workshop on Knowledge Graphs for Online Discourse Analysis (KnOD 2021, co-located with TheWebConf’21) https://ceur-ws.org/Vol-2877/preface.pdf https://knod2021.wordpress.com/   ABSTRACT Expressing opinions and interacting with others on the Web has led to the production of an abundance of online discourse data, such as claims and viewpoints on controversial topics, their sources and contexts . This data constitutes a valuable source of insights for studies into misinformation spread, bias reinforcement, echo chambers or political agenda setting. While knowledge graphs promise to provide the key to a Web of structured information, they are mainly focused on facts without keeping track of the diversity, connection or temporal evolution of online discourse data. As opposed to facts, claims are inherently more complex. Their interpretation strongly depends on the context and a vari...