Pular para o conteúdo principal

SPARQL-Star x Query using Context Meta-information (RDF-Star)

Utilizando o recurso de RDF-Star onde cada tripla pode ser anotada com predicado e valor

Testes via Apache Jena Fuseki no desktop

Instalação

JDK

https://medium.com/@fadirra/setting-up-jena-fuseki-with-update-in-windows-10-2c8a2802ee8f

Download para WIndows
Unzip
Cria a pasta data

cmd
cd C:\Users\.....\apache-jena-fuseki-4.3.2
fuseki-server --loc=data --update /meta_info

http://localhost:3030/index.html

DATASET

Testes


SPARQL EndPoint /meta_info/update


PREFIX ns: <http://example.org/ns#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-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 {ns:p1 ns:LIVING_IN ns:c1};
INSERT DATA {<<ns:p1 ns:LIVING_IN ns:c1>>  ns:date_of_start 2014};
INSERT DATA {ns:p1 ns:WORKING_IN ns:c2};
INSERT DATA {<<ns:p1 ns:WORKING_IN ns:c2>>  ns:date_of_start 2014};

INSERT DATA {ns:p1 ns:LIVING_IN ns:c3};
INSERT DATA {<<ns:p1 ns:LIVING_IN ns:c3>>  ns:date_of_start 2014};
INSERT DATA {ns:p1 ns:WORKING_IN ns:c3};
INSERT DATA {<<ns:p1 ns:WORKING_IN ns:c3>>  ns:date_of_start 2014};

INSERT DATA {ns:p3 ns:LIVING_IN ns:c1};
INSERT DATA {<<ns:p3 ns:LIVING_IN ns:c1>>  ns:date_of_start 2016};
INSERT DATA {ns:p3 ns:WORKING_IN ns:c3};
INSERT DATA {<<ns:p3 ns:WORKING_IN ns:c3>>  ns:date_of_start 2014};
INSERT DATA {ns:p1 ns:FRIENDS_WITH ns:p2};
INSERT DATA {<<ns:p1 ns:FRIENDS_WITH ns:p2>>  ns:date_of_start 2011};
INSERT DATA {ns:p3 ns:FRIENDS_WITH ns:p1};
INSERT DATA {<<ns:p3 ns:FRIENDS_WITH ns:p1>>  ns:date_of_start 2012};
INSERT DATA {ns:p3 ns:FRIENDS_WITH ns:p2};
INSERT DATA {<<ns:p3 ns:FRIENDS_WITH ns:p2>>  ns:date_of_start 2014};

--

SPARQL EndPoint /meta_info/query


PREFIX ns: <http://example.org/ns#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

# 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 ?o { ?s ?p ?o . }  

Exemplo do resultado em XML

    <result>
      <binding name="s">
        <triple>
          <subject>
            <uri>http://example.org/ns#p1</uri>
          </subject>
          <predicate>
            <uri>http://example.org/ns#WORKING_IN</uri>
          </predicate>
          <object>
            <uri>http://example.org/ns#c3</uri>
          </object>
        </triple>
      </binding>
      <binding name="p">
        <uri>http://example.org/ns#date_of_start</uri>
      </binding>
      <binding name="o">
        <literal datatype="http://www.w3.org/2001/XMLSchema#integer">2014</literal>
      </binding>
    </result>

Exemplo do resultado em JSON

      {
        "s": {
          "type": "triple" ,
          "value": {
            "subject":  { "type": "uri" , "value": "http://example.org/ns#p1" } ,
            "predicate": { "type": "uri" , "value": "http://example.org/ns#LIVING_IN" } ,
            "object":   { "type": "uri" , "value": "http://example.org/ns#c1" }
          }
        } ,
        "p": { "type": "uri" , "value": "http://example.org/ns#date_of_start" } ,
        "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2014" }
      } ,
      
--

SELECT ?s ?p ?c ?t
{ ?c rdf:type  ns:Country; ns:name 'United Kingdom'.
  <<?s ?p ?c>> ns:date_of_start 2014 .
  BIND(<< ?s ?p ?c>> AS ?t)}

--

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

--

SELECT ?p_name ?f_name ?o ?t2
WHERE {
    ?p rdf:type ns:Person; ns:name ?p_name.
    ?f2 ns:name ?f_name.
    <<?p ns:FRIENDS_WITH ?f1>>  ns:date_of_start ?o1.
    <<?p ns:FRIENDS_WITH ?f2>>  ns:date_of_start ?o2.
    BIND(<<?p ns:FRIENDS_WITH ?f2>> AS ?t2)
    FILTER (?o2 > ?o1) .
}

Resultado em JSON

{ "head": {
    "vars": [ "p_name" , "f_name" , "o" , "t2" ]
  } ,
  "results": {
    "bindings": [
      {
        "p_name": { "type": "literal" , "value": "Anna" } ,
        "f_name": { "type": "literal" , "value": "Harry" } ,
        "t2": {
          "type": "triple" ,
          "value": {
            "subject":  { "type": "uri" , "value": "http://example.org/ns#p3" } ,
            "predicate": { "type": "uri" , "value": "http://example.org/ns#FRIENDS_WITH" } ,
            "object":   { "type": "uri" , "value": "http://example.org/ns#p2" }
          }
        }
      }
    ]
  }
}
--

SELECT ?p1_name ?p2_name ?p3_name ?p4_name ?o ?t2
WHERE {
    ?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.
    <<?p1 ns:FRIENDS_WITH ?p3>>  ns:date_of_start ?o.
    <<?p2 ns:FRIENDS_WITH ?p4>>  ns:date_of_start ?o.
    BIND(<<?p ns:FRIENDS_WITH ?f2>> AS ?t2)
    FILTER (?p1 != ?p2) .
}

--

SELECT ?p1_name ?p2_name ?c1_name ?c2_name ?o ?t2
WHERE {
    ?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.
    <<?p1 ns:LIVING_IN ?c1>>  ns:date_of_start ?o.
    <<?p2 ns:LIVING_IN ?c2>>  ns:date_of_start ?o.
    BIND(<<?p2 ns:LIVING_IN ?c2>> AS ?t2)
    FILTER (?c1 != ?c2) .
}

--

SELECT DISTINCT ?s1_name ?rel1 ?o1_name ?s2_name ?rel2 ?o2_name ?o
WHERE {
    ?s1 ns:name ?s1_name.
    ?s2 ns:name ?s2_name.
    ?o1 ns:name ?o1_name.
    ?o2 ns:name ?o2_name.
    <<?s1 ?rel1 ?o1>>  ns:date_of_start ?o.
    <<?s2 ?rel2 ?o2>>  ns:date_of_start ?o.
      BIND(<<?s1 ?rel1 ?o1>> AS ?t1)
    BIND(<<?s2 ?rel2 ?o2>> AS ?t2)
    FILTER (?t1 != ?t2) .
}

--

SELECT ?p1_name ?p2_name ?since ?t
WHERE {
    ?p1 ns:FRIENDS_WITH+ ?p2.
    ?p1 rdf:type ns:Person; ns:name ?p1_name.
    ?p2 rdf:type ns:Person; ns:name ?p2_name.
    <<?p1 ns:FRIENDS_WITH ?p2>>  ns:date_of_start ?since.
      BIND(<<?p1 ns:FRIENDS_WITH ?p2>> AS ?t)
    FILTER (?since > 2010) .
}

--


SPARQL EndPoint /meta_info/update

PREFIX ns: <http://example.org/ns#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

INSERT DATA {<<ns:p1 ns:FRIENDS_OF ns:p2>>  ns:date_of_start 2018};
INSERT DATA {<<ns:p3 ns:FRIENDS_OF ns:p1>>  ns:date_of_start 2019} ;
INSERT DATA {<<ns:p3 ns:FRIENDS_OF ns:p2>>  ns:date_of_start 2017} ;
INSERT DATA {ns:p1 ns:FRIENDS_OF ns:p2};
INSERT DATA {ns:p3 ns:FRIENDS_OF ns:p1};
INSERT DATA {ns:p3 ns:FRIENDS_OF ns:p2};

SPARQL EndPoint /meta_info/query


PREFIX ns: <http://example.org/ns#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?since ?t
WHERE {
    ns:p3 ns:FRIENDS_OF+ ns:p2.
    <<?p1 ns:FRIENDS_OF ?p2>>  ns:date_of_start ?since.
      BIND(<<?p1 ns:FRIENDS_OF ?p2>> AS ?t)
    FILTER (?since > 2016) .
}

SELECT ?since ?t
WHERE {
    ns:p3 ns:FRIENDS_OF+ ns:p2.
    <<?p1 ns:FRIENDS_OF ?p2>>  ns:date_of_start ?since.
      BIND(<<?p1 ns:FRIENDS_OF ?p2>> AS ?t)
    FILTER (?since > 2017) .
}

As consultas do tipo property path em SPARQL e SPARQL-Star retornam apenas os nós inicial e final de um caminho e não permitem variáveis ​​em expressões regulares para os predicados dos caminhos. Dessa forma, as consultas de caminho não retornam todos os nós intermediários em cada caminho. Adicionalmente um caminho de triplas RDF não pode ser representado naturalmente no formato de resultados tabulares de SPARQL.Com isso não é possível associar as triplas RDF recuperadas com as triplas RDF-Star associadas aos pares chave/valor dos qualificadores. 

Comentários

  1. Sobre essa questão das consultas de caminho, abri essa thread no SPARQL-Star
    https://github.com/w3c/rdf-star/issues/248#issuecomment-1022943523

    Porém é um limitação do próprio SPARQL e não especificamente do modelo RDF-Star.

    ResponderExcluir

Postar um comentário

Sinta-se a vontade para comentar. Críticas construtivas são sempre bem vindas.

Postagens mais visitadas deste blog

Aula 12: WordNet | Introdução à Linguagem de Programação Python *** com NLTK

 Fonte -> https://youtu.be/0OCq31jQ9E4 A WordNet do Brasil -> http://www.nilc.icmc.usp.br/wordnetbr/ NLTK  synsets = dada uma palavra acha todos os significados, pode informar a língua e a classe gramatical da palavra (substantivo, verbo, advérbio) from nltk.corpus import wordnet as wn wordnet.synset(xxxxxx).definition() = descrição do significado É possível extrair hipernimia, hiponimia, antonimos e os lemas (diferentes palavras/expressões com o mesmo significado) formando uma REDE LEXICAL. Com isso é possível calcular a distância entre 2 synset dentro do grafo.  Veja trecho de código abaixo: texto = 'útil' print('NOUN:', wordnet.synsets(texto, lang='por', pos=wordnet.NOUN)) texto = 'útil' print('ADJ:', wordnet.synsets(texto, lang='por', pos=wordnet.ADJ)) print(wordnet.synset('handy.s.01').definition()) texto = 'computador' for synset in wn.synsets(texto, lang='por', pos=wn.NOUN):     print('DEF:',s...

truth makers AND truth bearers - Palestra Giancarlo no SBBD

Dando uma googada https://iep.utm.edu/truth/ There are two commonly accepted constraints on truth and falsehood:     Every proposition is true or false.         [Law of the Excluded Middle.]     No proposition is both true and false.         [Law of Non-contradiction.] What is the difference between a truth-maker and a truth bearer? Truth-bearers are either true or false; truth-makers are not since, not being representations, they cannot be said to be true, nor can they be said to be false . That's a second difference. Truth-bearers are 'bipolar,' either true or false; truth-makers are 'unipolar': all of them obtain. What are considered truth bearers?   A variety of truth bearers are considered – statements, beliefs, claims, assumptions, hypotheses, propositions, sentences, and utterances . When I speak of a fact . . . I mean the kind of thing that makes a proposition true or false. (Russe...

DGL-KE : Deep Graph Library (DGL)

Fonte: https://towardsdatascience.com/introduction-to-knowledge-graph-embedding-with-dgl-ke-77ace6fb60ef Amazon recently launched DGL-KE, a software package that simplifies this process with simple command-line scripts. With DGL-KE , users can generate embeddings for very large graphs 2–5x faster than competing techniques. DGL-KE provides users the flexibility to select models used to generate embeddings and optimize performance by configuring hardware, data sampling parameters, and the loss function. To use this package effectively, however, it is important to understand how embeddings work and the optimizations available to compute them. This two-part blog series is designed to provide this information and get you ready to start taking advantage of DGL-KE . Finally, another class of graphs that is especially important for knowledge graphs are multigraphs . These are graphs that can have multiple (directed) edges between the same pair of nodes and can also contain loops. The...