Pular para o conteúdo principal

SPARQL x Query using Context Meta-information (Triple Properties as Named Graphs)

Utilizando o recurso de Quad onde cada tripla pode ser identificada como um grafo

Testes via AllegroGraph WebView na VM032

PREFIX ns: <http://example.org/ns#>

INSERT DATA {ns:c1 rdf:type ns:Country; ns:name 'Germany';  ns:language 'German'; ns:continent 'Europe'; ns:population 83000000 };
INSERT DATA {ns:c2 rdf:type ns:Country; ns:name 'France'; ns:language 'French'; ns:continent 'Europe'; ns:population 67000000 };
INSERT DATA {ns:c3 rdf:type ns:Country; ns:name 'United Kingdom'; ns:language 'English'; ns:continent 'Europe'; ns:population: 66000000 };

INSERT DATA {ns:p1 rdf:type ns:Person; ns:name 'John' };
INSERT DATA {ns:p2 rdf:type ns:Person; ns:name 'Harry'};
INSERT DATA {ns:p3 rdf:type ns:Person; ns:name 'Anna'};

INSERT DATA {GRAPH ns:p1c1_1 {ns:p1 ns:LIVING_IN ns:c1}};
INSERT DATA {ns:p1c1_1  ns:date_of_start 2014};
INSERT DATA {GRAPH ns:p1c2_1 {ns:p1 ns:WORKING_IN ns:c2}};
INSERT DATA {ns:p1c2_1  ns:date_of_start 2014};

INSERT DATA {GRAPH ns:p1c3_1 { ns:p1 ns:LIVING_IN ns:c3}};
INSERT DATA {ns:p2c3_1  ns:date_of_start 2014};
INSERT DATA {GRAPH ns:p1c3_2 { ns:p1 ns:WORKING_IN ns:c3}};
INSERT DATA {ns:p2c3_1  ns:date_of_start 2014};

INSERT DATA {GRAPH ns:p3c1_1 { ns:p3 ns:LIVING_IN ns:c1}};
INSERT DATA {ns:p3c1_1  ns:date_of_start 2016};
INSERT DATA {GRAPH ns:p3c3_1 { ns:p3 ns:WORKING_IN ns:c3}};
INSERT DATA {ns:p3c3_1  ns:date_of_start 2014};

INSERT DATA {GRAPH ns:p1p2_1 { ns:p1 ns:FRIENDS_WITH ns:p2}};
INSERT DATA {ns:p1p2_1  ns:date_of_start 2011};
INSERT DATA {GRAPH ns:p3p1_1 { ns:p3 ns:FRIENDS_WITH ns:p1}};
INSERT DATA {ns:p3p1_1  ns:date_of_start 2012} ;
INSERT DATA {GRAPH ns:p3p2_1 {ns:p3 ns:FRIENDS_WITH ns:p2}};
INSERT DATA {ns:p3p2_1  ns:date_of_start 2014};

--

# This PREFIX causes the default graph of the dataset to include
# only triples that are not in a named graph.
# Otherwise, the default graph will include every triple.
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>

# View quads
SELECT ?s ?p ?o ?g {
  # default graph
  { ?s ?p ?o . }
  UNION
  # named graphs
  { GRAPH ?g { ?s ?p ?o . }  }
}

--

SELECT ?s ?p ?o ?g { GRAPH ?g { ?s ?p ?o . }  }

--

SELECT ?s ?p ?c ?g
{ ?c rdf:type ns:Country; ns:name 'United Kingdom'.
GRAPH ?g { ?s ?p ?c . }   
?g ns:date_of_start 2014}

--

SELECT ?p_name ?f_name ?o ?g
WHERE {
GRAPH ?g { ?p ns:FRIENDS_WITH ?f. }.
?p rdf:type ns:Person; ns:name ?p_name.
?f ns:name ?f_name.
?g ns:date_of_start ?o.
FILTER (?o > 2010) .
}

--

SELECT ?p_name ?f_name ?o2 ?g2
WHERE {
GRAPH ?g1 { ?p ns:FRIENDS_WITH ?f1. }.
GRAPH ?g2 { ?p ns:FRIENDS_WITH ?f2. }.
?p rdf:type ns:Person; ns:name ?p_name.
?f2 ns:name ?f_name.
?g1 ns:date_of_start ?o1.
?g2 ns:date_of_start ?o2.
FILTER (?o2 > ?o1) .
}

--

SELECT ?p1_name ?p2_name ?p3_name ?p4_name ?o ?g2
WHERE {
GRAPH ?g1 { ?p1 ns:FRIENDS_WITH ?p3. }.
GRAPH ?g2 { ?p2 ns:FRIENDS_WITH ?p4. }.
?p1 rdf:type ns:Person; ns:name ?p1_name.
?p2 rdf:type ns:Person; ns:name ?p2_name.
?p3 rdf:type ns:Person; ns:name ?p3_name.
?p4 rdf:type ns:Person; ns:name ?p4_name.
?g1 ns:date_of_start ?o.
?g2 ns:date_of_start ?o.
FILTER (?p1 != ?p2) .
}

--

SELECT ?p1_name ?p2_name ?c1_name ?c2_name ?o ?g2
WHERE {
GRAPH ?g1 { ?p1 ns:LIVING_IN ?c1. }.
GRAPH ?g2 { ?p2 ns:LIVING_IN ?c2. }.
?p1 rdf:type ns:Person; ns:name ?p1_name.
?p2 rdf:type ns:Person; ns:name ?p2_name.
?c1 rdf:type ns:Country; ns:name ?c1_name.
?c2 rdf:type ns:Country; ns:name ?c2_name.
?g1 ns:date_of_start ?o.
?g2 ns:date_of_start ?o.
FILTER (?p1 != ?p2) .
}

--

PREFIX ns: <http://example.org/ns#>

SELECT ?p1_name ?p2_name ?o ?g
WHERE {
GRAPH ?g { ?p1 ns:FRIENDS_WITH+ ?p2. }.
?p1 rdf:type ns:Person; ns:name ?p1_name.
?p2 rdf:type ns:Person; ns:name ?p2_name.
OPTIONAL {?g ns:date_of_start ?o. FILTER (?o > 2010) .}
}

--

PREFIX ns: <http://example.org/ns#>

INSERT DATA {GRAPH ns:p1p2_2 { ns:p1 ns:FRIENDS_OF ns:p2}};
INSERT DATA {GRAPH ns:p3p1_2 { ns:p3 ns:FRIENDS_OF ns:p1}};
INSERT DATA {ns:p1p2_2  ns:date_of_start 2018};
INSERT DATA {ns:p3p1_2  ns:date_of_start 2019} ;

SELECT ?o ?g
WHERE {
GRAPH ?g { ns:p3 ns:FRIENDS_OF+ ns:p2. }.
?g ns:date_of_start ?o.
}

OBS.: Property path entre diferentes "grafos" não funciona pq existe um caminho p3p1_2 - p3p1_2  que não é recuperado com a query acima

Outras referências com SPARQL

Como recuperar os relacionamentos entre classes

select distinct ?class {?s1 a ?class}

Como recuperar os relacionamentos entre classes

select distinct ?class1 ?p ?class2 {?s1 a ?class1; ?p ?s2 . ?s2 a ?class2.}  order by ?class1

Como recuperar os atributos das classes

select distinct ?class ?p {?s a ?class; ?p ?o . filter isLiteral (?o).}  order by ?class
# View triples filtrando palavras chaves no literal do objeto
SELECT ?s ?p ?o { ?s ?p ?o . (?s ?o) fti:match '<palavra chave>'.}
 
Os caminhos de propriedade são expressões regulares sobre o vocabulário I de todos os IRIs, para os quais “/” é concatenação, “|” disjunção, inversão “ˆ”, asterisco “∗” (zero ou mais ocorrências), “+” uma ou mais ocorrências e “?” zero ou uma ocorrência. 

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

Knowledge Graph Embedding with Triple Context - Leitura de Abstract

  Jun Shi, Huan Gao, Guilin Qi, and Zhangquan Zhou. 2017. Knowledge Graph Embedding with Triple Context. In Proceedings of the 2017 ACM on Conference on Information and Knowledge Management (CIKM '17). Association for Computing Machinery, New York, NY, USA, 2299–2302. https://doi.org/10.1145/3132847.3133119 ABSTRACT Knowledge graph embedding, which aims to represent entities and relations in vector spaces, has shown outstanding performance on a few knowledge graph completion tasks. Most existing methods are based on the assumption that a knowledge graph is a set of separate triples, ignoring rich graph features, i.e., structural information in the graph. In this paper, we take advantages of structures in knowledge graphs, especially local structures around a triple, which we refer to as triple context. We then propose a Triple-Context-based knowledge Embedding model (TCE). For each triple, two kinds of structure information are considered as its context in the graph; one is the out...

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