SparqlClient: Sparql Connection Client

SparqlClientR Documentation

Sparql Connection Client

Description

Low level Sparql connection client with query methods

Details

Methods

make_url(x)

construct the complete url

query(query, format = "json", ...)

query the endpoint

Examples

## Not run: 
# dbpedia
(x <- SparqlClient$new(url = "dbpedia.org", path = "sparql"))
x$query("SELECT * WHERE { ?s ?p ?o } OFFSET 100 LIMIT 10")

# open citations
(x <- SparqlClient$new(url = "opencitations.net", path = "sparql"))
x$url
x$path
x$scheme
x$make_base()
x$make_url()

query <- I("PREFIX+cito%3A+<http%3A%2F%2Fpurl.org%2Fspar%2Fcito%2F>%0APREFIX+dcterms%3A+<http%3A%2F%2Fpurl.org%2Fdc%2Fterms%2F>%0APREFIX+datacite%3A+<http%3A%2F%2Fpurl.org%2Fspar%2Fdatacite%2F>%0APREFIX+literal%3A+<http%3A%2F%2Fwww.essepuntato.it%2F2010%2F06%2Fliteralreification%2F>%0APREFIX+biro%3A+<http%3A%2F%2Fpurl.org%2Fspar%2Fbiro%2F>%0APREFIX+frbr%3A+<http%3A%2F%2Fpurl.org%2Fvocab%2Ffrbr%2Fcore%23>%0APREFIX+c4o%3A+<http%3A%2F%2Fpurl.org%2Fspar%2Fc4o%2F>%0ASELECT+%3Fcited+%3Fcited_ref+%3Ftitle+%3Furl+WHERE+%7B%0A%09<https%3A%2F%2Fw3id.org%2Foc%2Fcorpus%2Fbr%2F1>+cito%3Acites+%3Fcited+.%0A%09OPTIONAL+%7B+%0A%09%09<https%3A%2F%2Fw3id.org%2Foc%2Fcorpus%2Fbr%2F1>+frbr%3Apart+%3Fref+.%0A%09%09%3Fref+biro%3Areferences+%3Fcited+%3B%0A%09%09%09c4o%3AhasContent+%3Fcited_ref+%0A%09%7D%0A%09OPTIONAL+%7B+%3Fcited+dcterms%3Atitle+%3Ftitle+%7D%0A%09OPTIONAL+%7B%0A%09%09%3Fcited+datacite%3AhasIdentifier+%5B%0A%09%09%09datacite%3AusesIdentifierScheme+datacite%3Aurl+%3B%0A%09%09%09literal%3AhasLiteralValue+%3Furl%0A%09%09%5D%0A%09%7D%0A%7D")
x$query(query, verbose = TRUE)

# get PMID and PMCID identifiers from DOI
qry <- 'PREFIX datacite: <http://purl.org/spar/datacite/>
PREFIX literal: <http://www.essepuntato.it/2010/06/literalreification/>
SELECT ?paper ?pmid ?pmcid WHERE {
  ?paper datacite:hasIdentifier [ 
      datacite:usesIdentifierScheme datacite:doi ;
      literal:hasLiteralValue "10.1097/igc.0000000000000609"
  ] .
  
  OPTIONAL {
    ?paper datacite:hasIdentifier [ 
      datacite:usesIdentifierScheme datacite:pmid ;
      literal:hasLiteralValue ?pmid
    ] .
  }
  
  OPTIONAL {
    ?paper datacite:hasIdentifier [ 
      datacite:usesIdentifierScheme datacite:pmcid ;
      literal:hasLiteralValue ?pmcid
    ] .
  }
}'
x$query(qry, verbose = TRUE)

# with DSL
sparql_dsl("http://opencitations.net/sparql") %>%
 prefix(datacite = "http://purl.org/spar/datacite/", 
        literal = "http://www.essepuntato.it/2010/06/literalreification/") %>% 
 select(paper, pmid, pmcid) %>% 
 where(
  list(paper, datacite:usesIdentifierScheme datacite:doi, literal:hasLiteralValue "10.1097/igc.0000000000000609"),
  optional(
    paper, datacite:usesIdentifierScheme datacite:pmid, literal:hasLiteralValue pmid
  ),
  optional(
    paper, datacite:usesIdentifierScheme datacite:pmcid, literal:hasLiteralValue pmcid
  )
 )

## End(Not run)

ropenscilabs/sparqldsl documentation built on May 18, 2022, 8:32 p.m.