Coder Social home page Coder Social logo

vityok / cl-ntriples Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 9 KB

A simple parser for the N-Triples data format as defined by the W3C for storing RDF/Semantic information. N-Triples is a line-based, plain text format for encoding an RDF graph.

Common Lisp 100.00%
ntriples n-triples semantic-web rdf-triples

cl-ntriples's Introduction

CL-NTRIPLES provides a simple parser for the N-Triples data format as defined by the W3C for storing RDF/Semantic information. N-Triples is a line-based, plain text format for encoding an RDF graph.

Main entry function is PARSE-NT method that parses N-Triples from the given source. This method accepts a file pathname, an input stream, or a string.

Returns a list of triples consisting of three elements: subject, predicate, object. Subjects can be either an uriref or a nodeID. Objects can be of three types: uriref, nodeID or a literal. Depending on the type of the object it is encoded into an association list.

N-Triples data format standard definition is provided in the W3C documents:

Check also the Semantic Web page on CLiki.

Project page on Sourceforge.

Sample usage

CL-NTRIPLES Quickdocs is available through Quicklisp:

(ql:quickload :cl-ntriples)

CL-NTRIPLES was developed for a practical purpose of accessing the wealth of data accumulated by the DBPedia project. For example, let's query information about a Ukrainian city of Chernihiv (wiki, dbpedia):

(defvar page-url "http://dbpedia.org/data/Chernihiv.ntriples")
(defvar *res* (nt:parse-nt (drakma:http-request page-url)))
;; *res* now contains a list of triples, let's query some predicates
;; for brevity, predicates will defined as variables

(defconstant +prop-area-total-km+ "http://dbpedia.org/property/areaTotalKm")
(defconstant +rdf-label+ "http://www.w3.org/2000/01/rdf-schema#label")

;; querying predicates is now reduced to a simple function call:
;; nt:predicate? TRIPLES PREDICATE &key LANG DATA-TYPE

;; what is the city area in km2?
(nt:predicate? *res* +prop-area-total-km+)
=> (("http://dbpedia.org/resource/Chernihiv"
  "http://dbpedia.org/property/areaTotalKm"
  ((:LITERAL-STRING . "79")
   (:URIREF . "http://www.w3.org/2001/XMLSchema#int"))))

;; how do Japanese call this city?
(predicate? *res* +rdf-label+ :lang "ja")
=> (("http://dbpedia.org/resource/Chernihiv"
  "http://www.w3.org/2000/01/rdf-schema#label"
  (:LITERAL-STRING "チェルニーヒウ" :LANG "ja")))

Functions

Package provides following functions:

  • PARSE-NT src Parses and returns a list of triples

  • PREDICATE? triples predicate &key lang data-type filters out triples with matching predicates. Additional parameters (lang and data-type) can be used to limit returned triples to those with matching language and data type specifiers.

  • LITERAL-STRING triple returns the literal-string value of the given triple.

cl-ntriples's People

Contributors

vityok avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

robertbrook

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.