Pular para o conteúdo principal

Python - conexão Allegro e executar queries SPARQL e outros comandos da API no jupyter notebook

 

Instalação -> https://franz.com/agraph/support/documentation/current/python/install.html

pip install agraph-python

Guia de Referência da API -> https://franz.com/agraph/support/documentation/current/python/api.html

Tutorial -> https://franz.com/agraph/support/documentation/current/python/tutorial.html

No notebook jupyter  tem exemplos dos comandos para abrir conexão, preparar comandos, executar comandos, setar variável de ambiente, etc ...

addStatement     Add the supplied statement to the specified contexts in the repository.
addTriple            Add a single triple to the repository.
getStatements     Get all statements with a specific subject, predicate and/or object from the repository.

prepareBooleanQuery      Parse query into a boolean query object which can be executed against the triple store.
prepareGraphQuery        Parse query into a graph query object which can be executed against the triple store.
prepareTupleQuery         Parse query into a tuple query object which can be executed against the triple stroe.
prepareUpdate                 Parse query into an update query object which can be executed against the triple store.

executeBooleanQuery       Prepare and immediately evaluate a query that returns a boolean.
executeGraphQuery         Prepare and immediately evaluate a query that returns RDF.
executeTupleQuery           Prepare and immediately evaluate a query that returns tuples.
executeUpdate                   Prepare and immediately evaluate a SPARQL update query. 

evalFreeTextSearch          Return a list of statements for the given free-text pattern search.

To insert the data we have to iterate over the result and add each triple using addStatement() (or use an INSERT query).

SELECT: This kind of query returns a sequence of tuples, binding variables to matching elements of a search pattern. SELECT queries are created using prepareTupleQuery() and return results of type TupleQueryResult.

The ASK query returns a Boolean, depending on whether the triple pattern matched any triples. Queries of this type are created using prepareBooleanQuery().

The CONSTRUCT query creates triples by substantiating provided templates with values resulting from matching a pattern. Queries of this kind are created using prepareGraphQuery() and return a RepositoryResult - which is an iterator over the constructed triples.

The DESCRIBE query returns triples that ‘describe’ a given set of resources. Such queries are created using prepareGraphQuery() and return RepositoryResult objects.

Reasoner

conn.getStatements(s, p, o, includeInferred=True)

RDFS++ (rdfs e owl)
owl:inverseOf, subPropertyOf, inverseOf with subPropertyOf, sameAs, sameAs with inverseOf and subPropertyOf, type with subClassOf, type with range, type with domain, Transitivity with sameAs

Comentários

Postar um comentário

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

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