Git Product home page Git Product logo

flyingfish's Introduction

flyingfish

This project about:

  • Python language
  • RDF-databases (Redland)
  • mapping RDF data to Python classes

Flyingfish is written and tested as a part of Django-based site, used in ExtMem.com project.

Functionality

The lib binds Redland (RDF triple storage) to hi-level python classes. Current version is typeless and doesn't care about RDF-schema.

from flyingfish.client import RDFconnection
#to inticialize DB run once with startnew=True
connection = RDFconnection(model="test_storage1", storage="postgresql", startnew=False,
                           options = "host='127.0.0.1',database='rdfdb',user='root','password=''")
client = connection.client()


URI = "http://www.pleso.net/rdf/#"
#create named resource
root = client.get(URI + 'root')

person1 = client.get(URI + 'p1')
#attribute access to statements, useful for rendering in templates
person1.rdf_type = 'foaf:Person'
person1.foaf_name = 'Alex'
person1.ext_tag = 'developer'

person2 = client.get(URI + 'p2')
person2['rdf:type'] = 'foaf:Person'
person2['foaf:name'] = 'Nick'
person2['ext:tag'] = 'developer'
person2['ext:tag'] = 'designer'

person1['foaf:knows'] = person2

root.ext_all = URI + 'p1'
root['ext:all'] = person2

from flyingfish.utils import modeldump
print 'FULL DUMP \n', modeldump(client.model)

#get resource  by URI
resource = client.get(URI + 'p1')
print 'INTROSPECT RESOURCE BY URI \n',resource.cache_introspect()

people = client.query('foaf:Person', '?uri foaf:name "Nick"',["foaf"])
print 'SIMPLE QUERY RESULT \n', people

Output:

FULL DUMP 
Statement: {[http://www.pleso.net/rdf/#p1], [http://www.w3.org/1999/02/22-rdf-syntax-ns#type], [http://xmlns.com/foaf/0.1/Person]}
Statement: {[http://www.pleso.net/rdf/#p1], [http://xmlns.com/foaf/0.1/name], "Alex"}
Statement: {[http://www.pleso.net/rdf/#p1], [http://extmem.com/rdfs/ext/tag], "developer"}
Statement: {[http://www.pleso.net/rdf/#p2], [http://www.w3.org/1999/02/22-rdf-syntax-ns#type], [http://xmlns.com/foaf/0.1/Person]}
Statement: {[http://www.pleso.net/rdf/#p2], [http://xmlns.com/foaf/0.1/name], "Nick"}
Statement: {[http://www.pleso.net/rdf/#p2], [http://extmem.com/rdfs/ext/tag], "developer"}
Statement: {[http://www.pleso.net/rdf/#p2], [http://extmem.com/rdfs/ext/tag], "designer"}
Statement: {[http://www.pleso.net/rdf/#root], [http://extmem.com/rdfs/ext/all], "http://www.pleso.net/rdf/#p1"}
Statement: {[http://www.pleso.net/rdf/#root], [http://extmem.com/rdfs/ext/all], (r1229485140r7596r1)}
Statement: {[http://www.pleso.net/rdf/#p1], [http://xmlns.com/foaf/0.1/knows], (r1229485451r7881r1)}


INTROSPECT RESOURCE BY URI 
http://www.pleso.net/rdf/#p1 {
foaf:knows:                                     (r1229485451r7881r1)
rdf:type:                                       http://xmlns.com/foaf/0.1/Person
ext:tag:                                        developer
foaf:name:                                      Alex

}
SIMPLE QUERY RESULT 
http://www.pleso.net/rdf/#p2

Links:

flyingfish's People

Contributors

235 avatar

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.