├── pymantic
├── scripts
│ ├── __init__.py
│ ├── named_graph_to_nquads
│ └── bnf2html
├── tests
│ ├── __init__.py
│ ├── turtle_tests
│ │ ├── test-00.ttl
│ │ ├── bad-00.ttl
│ │ ├── bad-08.ttl
│ │ ├── test-08.ttl
│ │ ├── test-19.ttl
│ │ ├── test-24.ttl
│ │ ├── test-26.out
│ │ ├── bad-13.ttl
│ │ ├── test-07.ttl
│ │ ├── test-20.ttl
│ │ ├── test-21.ttl
│ │ ├── test-22.ttl
│ │ ├── test-23.out
│ │ ├── bad-03.ttl
│ │ ├── bad-09.ttl
│ │ ├── test-17.out
│ │ ├── bad-10.ttl
│ │ ├── bad-11.ttl
│ │ ├── bad-12.ttl
│ │ ├── test-06.ttl
│ │ ├── test-27.out
│ │ ├── bad-06.ttl
│ │ ├── test-19.out
│ │ ├── bad-02.ttl
│ │ ├── bad-07.ttl
│ │ ├── test-02.ttl
│ │ ├── test-26.ttl
│ │ ├── bad-05.ttl
│ │ ├── test-03.ttl
│ │ ├── test-06.out
│ │ ├── test-13.ttl
│ │ ├── test-20.out
│ │ ├── test-23.ttl
│ │ ├── bad-01.ttl
│ │ ├── bad-04.ttl
│ │ ├── test-08.out
│ │ ├── test-04.ttl
│ │ ├── test-17.ttl
│ │ ├── test-13.out
│ │ ├── bad-14.ttl
│ │ ├── test-27.ttl
│ │ ├── test-00.out
│ │ ├── test-04.out
│ │ ├── test-05.ttl
│ │ ├── test-18.ttl
│ │ ├── test-24.out
│ │ ├── test-01.ttl
│ │ ├── test-18.out
│ │ ├── test-02.out
│ │ ├── test-03.out
│ │ ├── test-01.out
│ │ ├── test-05.out
│ │ ├── test-11.out
│ │ ├── test-21.out
│ │ ├── test-22.out
│ │ ├── test-10.ttl
│ │ ├── test-12.out
│ │ ├── test-09.ttl
│ │ ├── test-25.ttl
│ │ ├── test-12.ttl
│ │ ├── test-29.out
│ │ ├── test-29.ttl
│ │ ├── test-11.ttl
│ │ ├── test-09.out
│ │ ├── test-07.out
│ │ ├── test-30.ttl
│ │ ├── test-10.out
│ │ ├── test-25.out
│ │ ├── test-30.out
│ │ ├── test-28-out.ttl
│ │ ├── README.txt
│ │ ├── rdfq-results.ttl
│ │ ├── test-28.out
│ │ ├── test-28.ttl
│ │ ├── manifest-bad.ttl
│ │ ├── rdfq-results.out
│ │ ├── rdf-schema.ttl
│ │ ├── rdfs-namespace.ttl
│ │ ├── manifest.ttl
│ │ ├── rdf-schema.out
│ │ ├── rdfs-namespace.out
│ │ └── Overview.html
│ ├── test_util.py
│ ├── test_SPARQL.py
│ ├── test_turtle.py
│ ├── test_parsers.py
│ ├── test_primitives.py
│ └── test_serializers.py
├── vocab
│ ├── __init__.py
│ └── skos.py
├── __init__.py
├── uri_schemes.py
├── util.py
├── change_tracking.py
├── serializers.py
└── sparql.py
├── setup.cfg
├── .gitignore
├── docs
├── modules
│ ├── rdf.rst
│ └── primitives.rst
├── contents.rst
├── index.rst
├── Makefile
└── conf.py
├── .hgignore
├── pymantic.wpr
├── examples
└── foaf-bond.ttl
├── README.rst
├── setup.py
└── LICENSE
/pymantic/scripts/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pymantic/tests/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pymantic/vocab/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [egg_info]
2 | tag_build = dev
3 | tag_svn_revision = true
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-00.ttl:
--------------------------------------------------------------------------------
1 | @prefix : <#> .
2 | [] :x :y .
3 |
--------------------------------------------------------------------------------
/pymantic/__init__.py:
--------------------------------------------------------------------------------
1 | #
2 | version = '0.1.1'
3 | release = version + 'alpha'
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-00.ttl:
--------------------------------------------------------------------------------
1 | # prefix name must end in a :
2 | @prefix a <#> .
3 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-08.ttl:
--------------------------------------------------------------------------------
1 | @keywords something.
2 | # @keywords is not in turtle
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | pymantic.egg-info
2 | *.pyc
3 | *.so
4 | include
5 | lib
6 | share
7 | docs/_build
8 | build
9 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-08.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 | :a :b ( ) .
3 |
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-19.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 |
3 | :a :b 1.0 .
4 |
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-24.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 | :a :b true .
3 | :c :d false .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-26.out:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/docs/modules/rdf.rst:
--------------------------------------------------------------------------------
1 | :mod:`pymantic.rdf`
2 | -------------------
3 |
4 | .. automodule:: pymantic.rdf
5 | :members:
6 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-13.ttl:
--------------------------------------------------------------------------------
1 | # <= is not in turtle
2 | @prefix : .
3 | :a <= :b .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-07.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 | :a :b ( "apple" "banana" ) .
3 |
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-20.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 |
3 | :a :b "" .
4 |
5 | :c :d """""" .
6 |
7 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-21.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 | :a :b 1.0 .
3 | :c :d 1 .
4 | :e :f 1.0e0 .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-22.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 | :a :b -1.0 .
3 | :c :d -1 .
4 | :e :f -1.0e0 .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-23.out:
--------------------------------------------------------------------------------
1 | "John said: \"Hello World!\"" .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-03.ttl:
--------------------------------------------------------------------------------
1 | # 'a' only allowed as a predicate
2 | @prefix : .
3 | a :a :b .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-09.ttl:
--------------------------------------------------------------------------------
1 | # implies is not in turtle
2 | @prefix : .
3 | :a => :b .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-17.out:
--------------------------------------------------------------------------------
1 | "a long\n\tliteral\nwith\nnewlines" .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-10.ttl:
--------------------------------------------------------------------------------
1 | # equivalence is not in turtle
2 | @prefix : .
3 | :a = :b .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-11.ttl:
--------------------------------------------------------------------------------
1 | # @forAll is not in turtle
2 | @prefix : .
3 | @forAll :x .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-12.ttl:
--------------------------------------------------------------------------------
1 | # @forSome is not in turtle
2 | @prefix : .
3 | @forSome :x .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-06.ttl:
--------------------------------------------------------------------------------
1 | # 'a' only allowed as a predicate
2 | @prefix : .
3 | :a a :b .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-27.out:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-06.ttl:
--------------------------------------------------------------------------------
1 | # is and of are not in turtle
2 | @prefix : .
3 | :a is :b of :c .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-19.out:
--------------------------------------------------------------------------------
1 | "1.0"^^ .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-02.ttl:
--------------------------------------------------------------------------------
1 | # Forbidden by RDF - predicate cannot be blank
2 | @prefix : .
3 | :a [] :b .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-07.ttl:
--------------------------------------------------------------------------------
1 | # paths are not in turtle
2 | @prefix : .
3 | :a.:b.:c .
4 | :a^:b^:c .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-02.ttl:
--------------------------------------------------------------------------------
1 | # Test , operator
2 | @prefix : .
3 | :a :b :c,
4 | :d,
5 | :e .
6 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-26.ttl:
--------------------------------------------------------------------------------
1 | # comment line with no final newline test
2 | @prefix : .
3 | :a :b :c .
4 | #foo
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-05.ttl:
--------------------------------------------------------------------------------
1 | # N3 {}s are not in Turtle
2 | @prefix : .
3 | { :a :b :c . } :d :e .
4 |
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-03.ttl:
--------------------------------------------------------------------------------
1 | # Test ; operator
2 | @prefix : .
3 | :a :b :c ;
4 | :d :e ;
5 | :f :g .
6 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-06.out:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-13.ttl:
--------------------------------------------------------------------------------
1 | # Test for : allowed
2 | @prefix : .
3 |
4 | [] : [] .
5 |
6 | : : : .
7 |
8 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-20.out:
--------------------------------------------------------------------------------
1 | "" .
2 | "" .
3 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-23.ttl:
--------------------------------------------------------------------------------
1 | # Test long literal
2 | @prefix : .
3 | :a :b """John said: "Hello World!\"""" .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-01.ttl:
--------------------------------------------------------------------------------
1 | # Forbidden by RDF - predicate cannot be blank
2 | @prefix : .
3 | :a [ :b :c ] :d .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-04.ttl:
--------------------------------------------------------------------------------
1 | # No comma is allowed in collections
2 | @prefix : .
3 | :a :b ( "apple", "banana" ) .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-08.out:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-04.ttl:
--------------------------------------------------------------------------------
1 | # Test empty [] operator; not allowed as predicate
2 | @prefix : .
3 | [] :a :b .
4 | :c :d [] .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-17.ttl:
--------------------------------------------------------------------------------
1 | # Test long literal
2 | @prefix : .
3 | :a :b """a long
4 | literal
5 | with
6 | newlines""" .
7 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-13.out:
--------------------------------------------------------------------------------
1 | _:genid1 _:genid2 .
2 | .
3 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/bad-14.ttl:
--------------------------------------------------------------------------------
1 | # Test long literals with missing end
2 | @prefix : .
3 | :a :b """a long
4 | literal
5 | with
6 | newlines
7 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-27.ttl:
--------------------------------------------------------------------------------
1 | @prefix foo: .
2 | @prefix foo: .
3 |
4 | foo:blah foo:blah foo:blah .
5 |
6 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-00.out:
--------------------------------------------------------------------------------
1 | _:genid1 .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-04.out:
--------------------------------------------------------------------------------
1 | _:genid1 .
2 | _:genid2 .
3 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-05.ttl:
--------------------------------------------------------------------------------
1 | # Test non empty [] operator; not allowed as predicate
2 | @prefix : .
3 | [ :a :b ] :c :d .
4 | :e :f [ :g :h ] .
5 |
--------------------------------------------------------------------------------
/.hgignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 | *.pyc
3 | *~
4 | *.wpu
5 | build
6 | _build
7 | include
8 | data
9 | dist
10 | lib
11 | bin
12 | *.swp
13 | *.db
14 | .DS_Store
15 | pymantic.egg-info
16 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-18.ttl:
--------------------------------------------------------------------------------
1 | @prefix : .
2 |
3 | :a :b """\nthis \ris a \U00015678long\t
4 | literal\uABCD
5 | """ .
6 |
7 | :d :e """\tThis \uABCDis\r \U00015678another\n
8 | one
9 | """ .
10 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-24.out:
--------------------------------------------------------------------------------
1 | "true"^^ .
2 | "false"^^ .
3 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-01.ttl:
--------------------------------------------------------------------------------
1 | # Test @prefix and qnames
2 | @prefix : .
3 | @prefix a: .
4 | @prefix b: .
5 | :a :b :c .
6 | a:a a:b a:c .
7 | :a a:a b:a .
8 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-18.out:
--------------------------------------------------------------------------------
1 | "\nthis \ris a \U00015678long\t\nliteral\uABCD\n" .
2 | "\tThis \uABCDis\r \U00015678another\n\none\n" .
3 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-02.out:
--------------------------------------------------------------------------------
1 | .
2 | .
3 | .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-03.out:
--------------------------------------------------------------------------------
1 | .
2 | .
3 | .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-01.out:
--------------------------------------------------------------------------------
1 | .
2 | .
3 | .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-05.out:
--------------------------------------------------------------------------------
1 | _:genid1 .
2 | _:genid1 .
3 | _:genid2 .
4 | _:genid2 .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-11.out:
--------------------------------------------------------------------------------
1 | "a" .
2 | "b" .
3 | "c" .
4 | "d" .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-21.out:
--------------------------------------------------------------------------------
1 | "1.0"^^ .
2 | "1"^^ .
3 | "1.0e0"^^ .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-22.out:
--------------------------------------------------------------------------------
1 | "-1.0"^^ .
2 | "-1"^^ .
3 | "-1.0e0"^^ .
4 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-10.ttl:
--------------------------------------------------------------------------------
1 | 000000 .
2 | 0 .
3 | 000001 .
4 | 2 .
5 | 4 .
6 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-12.out:
--------------------------------------------------------------------------------
1 | "1" .
2 | "2" .
3 | "def" .
4 | "678" .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-09.ttl:
--------------------------------------------------------------------------------
1 | # Test integer datatyped literals using an OWL cardinality constraint
2 | @prefix owl: .
3 |
4 | # based on examples in the OWL Reference
5 |
6 | _:hasParent a owl:ObjectProperty .
7 |
8 | [] a owl:Restriction ;
9 | owl:onProperty _:hasParent ;
10 | owl:maxCardinality 2 .
11 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-25.ttl:
--------------------------------------------------------------------------------
1 | # comment test
2 | @prefix : .
3 | :a :b :c . # end of line comment
4 | :d # ignore me
5 | :e # and me
6 | :f # and me
7 | .
8 | :g :h #ignore me
9 | :i, # and me
10 | :j . # and me
11 |
12 | :k :l :m ; #ignore me
13 | :n :o ; # and me
14 | :p :q . # and me
15 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-12.ttl:
--------------------------------------------------------------------------------
1 | # Tests for rdf:_ and other qnames starting with _
2 | @prefix rdf: .
3 | @prefix ex: .
4 | @prefix : .
5 |
6 | ex:foo rdf:_1 "1" .
7 | ex:foo rdf:_2 "2" .
8 | ex:foo :_abc "def" .
9 | ex:foo :_345 "678" .
10 |
--------------------------------------------------------------------------------
/docs/contents.rst:
--------------------------------------------------------------------------------
1 | ===============================
2 | Pymantic documentation contents
3 | ===============================
4 |
5 | .. toctree::
6 | :maxdepth: 3
7 |
8 | index
9 | modules/primitives
10 | modules/rdf
11 |
12 |
13 | Indices, glossary and tables
14 | ============================
15 |
16 | * :ref:`genindex`
17 | * :ref:`modindex`
18 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-29.out:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-29.ttl:
--------------------------------------------------------------------------------
1 | .
2 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-11.ttl:
--------------------------------------------------------------------------------
1 | # Tests for - and _ in names, qnames
2 | @prefix ex1: .
3 | @prefix ex-2: .
4 | @prefix ex3_: .
5 | @prefix ex4-: .
6 |
7 | ex1:foo-bar ex1:foo_bar "a" .
8 | ex-2:foo-bar ex-2:foo_bar "b" .
9 | ex3_:foo-bar ex3_:foo_bar "c" .
10 | ex4-:foo-bar ex4-:foo_bar "d" .
11 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-09.out:
--------------------------------------------------------------------------------
1 | _:hasParent .
2 | _:genid1 .
3 | _:genid1 _:hasParent .
4 | _:genid1 "2"^^ .
5 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-07.out:
--------------------------------------------------------------------------------
1 | _:genid1 "banana" .
2 | _:genid1 .
3 | _:genid2 "apple" .
4 | _:genid2 _:genid1 .
5 | _:genid2 .
6 |
--------------------------------------------------------------------------------
/pymantic/vocab/skos.py:
--------------------------------------------------------------------------------
1 | from pymantic.rdf import Resource, register_class
2 |
3 | SKOS_NS = "http://www.w3.org/2004/02/skos/core#"
4 | NS_DICT = dict(skos = SKOS_NS)
5 |
6 | class SKOSResource(Resource):
7 | namespaces = NS_DICT
8 |
9 | scaler = ['skos:prefLabel']
10 |
11 | @register_class("skos:Concept")
12 | class Concept(SKOSResource):
13 | pass
14 |
15 | @register_class("skos:ConceptScheme")
16 | class ConceptScheme(SKOSResource):
17 | pass
18 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-30.ttl:
--------------------------------------------------------------------------------
1 | # In-scope base URI is http://www.w3.org/2001/sw/DataAccess/df1/tests/ at this point
2 | .
3 | @base .
4 | # In-scope base URI is http://example.org/ns/ at this point
5 | .
6 | @base .
7 | # In-scope base URI is http://example.org/ns/foo/ at this point
8 | .
9 | @prefix : .
10 | :a4 :b4 :c4 .
11 | @prefix : .
12 | :a5 :b5 :c5 .
13 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-10.out:
--------------------------------------------------------------------------------
1 | "000000"^^ .
2 | "0"^^ .
3 | "000001"^^ .
4 | "2"^^ .
5 | "4"^^ .
6 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-25.out:
--------------------------------------------------------------------------------
1 | .
2 | .
3 | .
4 | .
5 | .
6 | .
7 | .
8 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-30.out:
--------------------------------------------------------------------------------
1 | .
2 | .
3 | .
4 | .
5 | .
6 |
--------------------------------------------------------------------------------
/pymantic.wpr:
--------------------------------------------------------------------------------
1 | #!wing
2 | #!version=4.0
3 | ##################################################################
4 | # Wing IDE project file #
5 | ##################################################################
6 | [project attributes]
7 | proj.directory-list = [{'dirloc': loc('.'),
8 | 'excludes': (),
9 | 'filter': '*',
10 | 'include_hidden': False,
11 | 'recursive': True,
12 | 'watch_for_changes': True}]
13 | proj.file-type = 'shared'
14 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-28-out.ttl:
--------------------------------------------------------------------------------
1 | @base .
2 | @prefix rdf: <../../../../../1999/02/22-rdf-syntax-ns#> .
3 |
4 |
5 | 2.345, 1, 1.0, 1., 1.000000000, 2.3, 2.234000005, 2.2340000005, 2.23400000005, 2.234000000005, 2.2340000000005, 2.23400000000005, 2.234000000000005, 2.2340000000000005, 2.23400000000000005, 2.234000000000000005, 2.2340000000000000005, 2.23400000000000000005, 2.234000000000000000005, 2.2340000000000000000005, 2.23400000000000000000005, 1.2345678901234567890123457890 .
6 |
7 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/README.txt:
--------------------------------------------------------------------------------
1 | These are the tests for the Turtle Terse RDF Triple Language
2 | that must be passed by conformant systems. See
3 | http://www.dajobe.org/2004/01/turtle/
4 | for the full conformance information.
5 |
6 | The format is a set of good tests and bad tests.
7 |
8 | Good tests are a pair of files:
9 | abc.ttl abc.out
10 | which are the input Turtle file and the expected output RDF triples,
11 | written in N-Triples.
12 |
13 | bad tests are of the form
14 | bad-XX.ttl
15 | which must fail.
16 |
17 | The tests should be performed with an assumed base URI
18 | of http://www.w3.org/2001/sw/DataAccess/df1/tests/
19 |
20 | Dave
21 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. _index:
2 |
3 | ********
4 | Pymantic
5 | ********
6 |
7 | Pymantic is a pythonic and easy-to-use library for working with `Resource Description Framework (RDF) `_ data.
8 |
9 | Examples
10 | ========
11 |
12 |
13 | Reading RDF data in N-Triples
14 | -----------------------------
15 | .. doctest::
16 |
17 | from pymantic.parsers import *
18 |
19 | with open("triples.nt") as f:
20 | graph = parse_ntriples(f)
21 |
22 |
23 | .. _getting_involved:
24 |
25 | Getting Involved
26 | ================
27 |
28 |
29 | GitHub project page
30 | -------------------
31 |
32 | Fork it, add features, wallow in the code, find out what is being worked on
33 |
34 | `github.com/norcalrdf/pymantic `_.
35 |
36 | Feedback (Bugs)
37 | ---------------
38 |
39 | Submit bugs in our `issue tracker `_.
40 |
41 | Discuss
42 | -------
43 |
44 | * `pymantic users mailing list `_.
45 | * `pymantic development mailing list `_.
46 |
--------------------------------------------------------------------------------
/pymantic/uri_schemes.py:
--------------------------------------------------------------------------------
1 | """A complete list of URI schemes registered as of Sept 26th, 2008, used when
2 | parsing CURIEs to differentiate explicit URIs from CURIEs."""
3 |
4 | schemes = ['aaa',
5 | 'aaas',
6 | 'acap',
7 | 'cap',
8 | 'cid',
9 | 'crid',
10 | 'data',
11 | 'dav',
12 | 'dict',
13 | 'dns',
14 | 'fax',
15 | 'file',
16 | 'ftp',
17 | 'go',
18 | 'gopher',
19 | 'h323',
20 | 'http',
21 | 'https',
22 | 'icap',
23 | 'im',
24 | 'imap',
25 | 'info',
26 | 'ipp',
27 | 'iris',
28 | 'iris.beep',
29 | 'iris.xpc',
30 | 'iris.xpcs',
31 | 'iris.lwz',
32 | 'ldap',
33 | 'mailto',
34 | 'mid',
35 | 'modem',
36 | 'msrp',
37 | 'msrps',
38 | 'mtqp',
39 | 'mupdate',
40 | 'news',
41 | 'nfs',
42 | 'nntp',
43 | 'opaquelocktoken',
44 | 'pop',
45 | 'pres',
46 | 'rtsp',
47 | 'service',
48 | 'shttp',
49 | 'sip',
50 | 'sips',
51 | 'snmp',
52 | 'soap.beep',
53 | 'soap.beeps',
54 | 'tag',
55 | 'tel',
56 | 'telnet',
57 | 'tftp',
58 | 'thismessage',
59 | 'tip',
60 | 'tv',
61 | 'urn',
62 | 'vemmi',
63 | 'xmlrpc.beep',
64 | 'xmlrpc.beeps',
65 | 'xmpp',
66 | 'z39.50r',
67 | 'z39.50s',
68 | 'afs',
69 | 'dtn',
70 | 'iax',
71 | 'mailserver',
72 | 'pack',
73 | 'tn3270',
74 | 'prospero',
75 | 'snews',
76 | 'videotex',
77 | 'wais',]
78 |
--------------------------------------------------------------------------------
/examples/foaf-bond.ttl:
--------------------------------------------------------------------------------
1 | # First, we declare some useful URL prefixes.
2 |
3 | @prefix rdf: .
4 | @prefix rdfs: .
5 | @prefix foaf: .
6 | @prefix : .
7 |
8 | # Second, we declare enough of a class hierarchy to get us somewhere.
9 |
10 | foaf:Agent a rdfs:Class ;
11 | rdfs:subClassOf rdf:Resource .
12 |
13 | foaf:Person a rdfs:Class ;
14 | rdfs:subClassOf foaf:Agent .
15 |
16 | foaf:Organization a rdfs:Class ;
17 | rdfs:subClassOf foaf:Agent .
18 |
19 | # Finally, we're ready to declare our data.
20 |
21 | :HMSS a foaf:Organization ;
22 | foaf:name "Her Majesty's Secret Service" ;
23 | foaf:nick "HMSS" ;
24 | foaf:member :M ;
25 | foaf:member :Q ;
26 | foaf:member :Bond ;
27 | foaf:member :Kerim .
28 |
29 | :M a foaf:Person ;
30 | foaf:name "M" ;
31 | foaf:knows :Q ;
32 | foaf:knows :Bond ;
33 | foaf:knows :Kerim .
34 |
35 | :Q a foaf:Person ;
36 | foaf:name "Q" ;
37 | foaf:knows :M ;
38 | foaf:knows :Bond .
39 |
40 | :Bond a foaf:Person ;
41 | foaf:name "James Bond" ;
42 | foaf:knows :M ;
43 | foaf:knows :Q .
44 |
45 | :Kerim a foaf:Person ;
46 | foaf:name "Darko Kerim" ;
47 | foaf:knows :M .
48 |
--------------------------------------------------------------------------------
/pymantic/scripts/named_graph_to_nquads:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import optparse
3 | import os.path
4 | import pymantic
5 | import rdflib
6 | import urllib
7 |
8 | if __name__ == '__main__':
9 | usage = """usage: %prog [options] filename1 filename2 ...
10 | Reads in RDF graphs and reserializes them as nquads to stdout, using the basename of each filename as the graph name."""
11 | parser = optparse.OptionParser(usage = usage)
12 |
13 | parser.add_option('-f', '--input-format', dest='input_format', default='application/rdf+xml',
14 | help='The content type of the input graphs. Default: application/rdf+xml')
15 | parser.add_option('-p', '--plain-filenames', dest='unquote',
16 | default=True, action='store_false',
17 | help="Are the filenames graph names, or do they need to be urllib.unquote'd?")
18 |
19 | (options, args) = parser.parse_args()
20 |
21 | for filename in args:
22 | graph_name = urllib.unquote(os.path.basename(filename)) if options.unquote\
23 | else os.path.basename(filename)
24 | graph = rdflib.ConjunctiveGraph()
25 | rdf_in = open(filename, 'rb')
26 | graph.parse(rdf_in, publicID=graph_name,
27 | format=pymantic.content_type_to_rdflib_format[options.input_format])
28 | print graph.serialize(format = 'nq')
29 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | ========
2 | Pymantic
3 | ========
4 | ---------------------------------------
5 | Semantic Web and RDF library for Python
6 | ---------------------------------------
7 |
8 |
9 | Quick Start
10 | ===========
11 | ::
12 |
13 | >>> from pymantic.rdf import *
14 | >>> from pymantic.parsers import turtle_parser
15 | >>> from urllib2 import urlopen
16 | >>> Resource.prefixes['foaf'] = Prefix('http://xmlns.com/foaf/0.1/')
17 | >>> graph = turtle_parser.parse(urlopen('https://raw.github.com/norcalrdf/pymantic/master/examples/foaf-bond.ttl'))
18 | >>> bond_james = Resource(graph, 'http://example.org/stuff/Bond')
19 | >>> print "%s knows:" % (bond_james.get_scalar('foaf:name'),)
20 | >>> for person in bond_james['foaf:knows']:
21 | print person.get_scalar('foaf:name')
22 |
23 |
24 |
25 | Requirements
26 | ============
27 |
28 | Pymantic requires Python 2.6 or higher. Lepl is used for the Turtle and NTriples parser. httplib2 is used for HTTP
29 | requests and the SPARQL client. simplejson and lxml are required by the SPARQL client as well.
30 |
31 |
32 | Install
33 | =======
34 |
35 | ::
36 |
37 | $ python setup.py install
38 |
39 | This will install Pymantic and all its dependencies.
40 |
41 |
42 | Documentation
43 | =============
44 |
45 | Generating a local copy of the documentation requires Sphinx:
46 |
47 | ::
48 |
49 | $ easy_install Sphinx
50 |
51 |
52 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/rdfq-results.ttl:
--------------------------------------------------------------------------------
1 | # from http://www.w3.org/2003/03/rdfqr-tests/recording-query-results.html
2 |
3 | @prefix rdf: .
4 | @prefix rs: .
5 |
6 |
7 | <> rdf:type rs:ResultSet ;
8 | rs:size 4 ;
9 | rs:resultVariable "x" ; rs:resultVariable "y" ;
10 | rs:solution
11 | [ rdf:type rs:ResultSolution ;
12 | rs:binding [ rs:variable "x" ; rs:value 123 ] ;
13 | rs:binding [ rs:variable "y" ; rs:value ]
14 | ] ;
15 |
16 | rs:solution
17 | [ rdf:type rs:ResultSolution ;
18 | rs:binding [ rs:variable "x" ;
19 | rs:value "2003-01-21" ] ;
20 | rs:binding [ rs:variable "y" ;
21 | rs:value ]
22 | ] ;
23 |
24 | rs:solution
25 | [ rdf:type rs:ResultSolution ;
26 | rs:binding [ rs:variable "x" ;
27 | rs:value "anon1" ] ;
28 | rs:binding [ rs:variable "y" ;
29 | rs:value _:a ]
30 | ] ;
31 |
32 | rs:solution
33 | [ rdf:type rs:ResultSolution ;
34 | rs:binding [ rs:variable "x" ;
35 | rs:value "anon2" ] ;
36 | rs:binding [ rs:variable "y" ;
37 | rs:value _:a ]
38 | ] ;
39 | .
40 |
--------------------------------------------------------------------------------
/pymantic/tests/test_util.py:
--------------------------------------------------------------------------------
1 | from nose.tools import *
2 | from pymantic.util import *
3 |
4 | def test_normalize_iri_no_escapes():
5 | uri = 'http://example.com/foo/bar?garply=aap&maz=bies'
6 | normalized = normalize_iri(uri)
7 | assert normalized == u'http://example.com/foo/bar?garply=aap&maz=bies'
8 | assert normalized == normalize_iri(normalized)
9 | assert quote_normalized_iri(normalized) == uri
10 |
11 | def test_normalize_iri_escaped_slash():
12 | uri = 'http://example.com/foo%2Fbar?garply=aap&maz=bies'
13 | normalized = normalize_iri(uri)
14 | print normalized
15 | assert normalized == u'http://example.com/foo%2Fbar?garply=aap&maz=bies'
16 | assert normalized == normalize_iri(normalized)
17 | assert quote_normalized_iri(normalized) == uri
18 |
19 | def test_normalize_iri_escaped_ampersand():
20 | uri = 'http://example.com/foo/bar?garply=aap%26yak&maz=bies'
21 | normalized = normalize_iri(uri)
22 | assert normalized == u'http://example.com/foo/bar?garply=aap%26yak&maz=bies'
23 | assert normalized == normalize_iri(normalized)
24 | assert quote_normalized_iri(normalized) == uri
25 |
26 | def test_normalize_iri_escaped_international():
27 | uri = 'http://example.com/foo/bar?garply=aap&maz=bi%C3%89s'
28 | normalized = normalize_iri(uri)
29 | print repr(normalized)
30 | assert normalized == u'http://example.com/foo/bar?garply=aap&maz=bi\u00C9s'
31 | assert normalized == normalize_iri(normalized)
32 | assert quote_normalized_iri(normalized) == uri
33 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import sys, os
2 |
3 | from setuptools import setup
4 |
5 | from pymantic import version
6 |
7 | setup(name='pymantic',
8 | version=version,
9 | description="Semantic Web and RDF library for Python",
10 | long_description="""""",
11 | classifiers=['Development Status :: 3 - Alpha',
12 | 'Intended Audience :: Developers',
13 | 'License :: OSI Approved :: BSD License',
14 | 'Topic :: Internet :: WWW/HTTP',
15 | 'Topic :: Scientific/Engineering :: Information Analysis',
16 | 'Topic :: Text Processing :: Markup',
17 | ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
18 | keywords='RDF N3 Turtle Semantics Web3.0',
19 | author='Gavin Carothers, Nick Pilon',
20 | author_email='gavin@carothers.name, npilon@gmail.com',
21 | url='http://github.com/oreillymedia/pymantic',
22 | license='BSD',
23 | packages=['pymantic'],
24 | include_package_data=True,
25 | zip_safe=False,
26 | test_suite='nose.collector',
27 | install_requires=[
28 | 'httplib2',
29 | 'lxml',
30 | 'mock_http',
31 | 'pytz',
32 | 'simplejson',
33 | 'lepl',
34 | 'rdflib'
35 | ],
36 | entry_points="""
37 | # -*- Entry points: -*-
38 | """,
39 | scripts = [
40 | 'pymantic/scripts/named_graph_to_nquads',
41 | 'pymantic/scripts/bnf2html',
42 | ],
43 | )
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009-2011, O'Reilly Media, Inc, Gavin Carothers, Nick Pilon
2 | and contributors
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice,
9 | this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 | * Neither the name of the author or contributors nor the names of its contributors
14 | may be used to endorse or promote products derived from this software without
15 | specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/docs/modules/primitives.rst:
--------------------------------------------------------------------------------
1 | :mod:`pymantic.primitives`
2 | --------------------------
3 |
4 | This module provides a Python implementation of the
5 | `RDF Interfaces `_ defined by the W3C.
6 | Also extends that API in places to allow for Datasets and Quads. The goal is to
7 | provide a simple API for working directly with Triples, and RDF Terms.
8 |
9 | .. automodule:: pymantic.primitives
10 |
11 | Data Structures
12 | ===============
13 |
14 | .. warning:: Currently Pyamntic does *NOT* restrict data structures to the RDF data model.
15 | For example Literals are allowed in the subject and predicate position, seralizing
16 | these is imposible
17 |
18 | .. autoclass:: Triple
19 |
20 | .. autoclass:: Graph
21 | :members:
22 |
23 | Non-RDF Interfaces Classes
24 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
25 |
26 | .. autoclass:: Quad
27 |
28 | .. autoclass:: Dataset
29 | :members:
30 |
31 | RDF Terms
32 | =========
33 |
34 | .. autoclass:: Literal
35 |
36 | .. autoclass:: NamedNode
37 |
38 | .. autoclass:: BlankNode
39 |
40 |
41 | RDF Enviroment Interfaces
42 | =========================
43 |
44 | .. autoclass:: RDFEnvironment
45 | :show-inheritance:
46 | :members:
47 | :undoc-members:
48 |
49 | .. autoclass:: PrefixMap
50 | :members:
51 |
52 | .. autoclass:: TermMap
53 | :members:
54 |
55 | .. autoclass:: Profile
56 | :members:
57 |
58 | Helper Functions
59 | ================
60 |
61 | .. autofunction:: is_language
62 |
63 | .. autofunction:: lang_match
64 |
65 | .. autofunction:: parse_curie
66 |
67 | .. autofunction:: parse_curies
68 |
69 | .. autofunction:: to_curie
70 |
71 |
--------------------------------------------------------------------------------
/pymantic/util.py:
--------------------------------------------------------------------------------
1 | """Utility functions used throughout pymantic."""
2 |
3 | __all__ = ['en', 'de', 'one_or_none', 'normalize_iri', 'quote_normalized_iri',]
4 |
5 | import re
6 | from urllib import quote
7 |
8 | def en(value):
9 | """Returns an RDF literal from the en language for the given value."""
10 | from pymantic.primitives import Literal
11 | return Literal(value, language='en')
12 |
13 | def de(value):
14 | """Returns an RDF literal from the de language for the given value."""
15 | from pymantic.primitives import Literal
16 | return Literal(value, language='de')
17 |
18 | def one_or_none(values):
19 | """Fetch the first value from values, or None if values is empty. Raises
20 | ValueError if values has more than one thing in it."""
21 | if not values:
22 | return None
23 | if len(values) > 1:
24 | raise ValueError('Got more than one value.')
25 | return values[0]
26 |
27 | percent_encoding_re = re.compile(r'(?:%[a-fA-F0-9][a-fA-F0-9])+')
28 |
29 | reserved_in_iri = ["%", ":", "/", "?", "#", "[", "]", "@", "!", "$", "&", "'",\
30 | "(", ")", "*", "+", ",", ";", "="]
31 |
32 | def percent_decode(regmatch):
33 | encoded = ''
34 | for group in regmatch.group(0)[1:].split('%'):
35 | encoded += chr(int(group, 16))
36 | uni = encoded.decode('utf-8')
37 | for res in reserved_in_iri:
38 | uni = uni.replace(res, '%%%02X' % ord(res))
39 | return uni
40 |
41 | def normalize_iri(iri):
42 | """Normalize an IRI using the Case Normalization (5.3.2.1) and
43 | Percent-Encoding Normalization (5.3.2.3) from RFC 3987. The IRI should be a
44 | unicode object."""
45 | return percent_encoding_re.sub(percent_decode, iri)
46 |
47 | def percent_encode(char):
48 | return ''.join('%%%02X' % ord(char) for char in char.encode('utf-8'))
49 |
50 | def quote_normalized_iri(normalized_iri):
51 | """Percent-encode a normalized IRI; IE, all reserved characters are presumed
52 | to be themselves and not percent encoded. All other unsafe characters are
53 | percent-encoded."""
54 | normalized_uri = ''.join(percent_encode(char) if ord(char) > 127 else char for\
55 | char in normalized_iri)
56 | return quote(normalized_uri, safe=''.join(reserved_in_iri))
57 |
--------------------------------------------------------------------------------
/pymantic/change_tracking.py:
--------------------------------------------------------------------------------
1 | from primitives import Graph, BlankNode, Triple
2 | from rdf import Resource, register_class
3 |
4 |
5 | class ChangeTrackingGraph(Graph):
6 |
7 | def __init__(self, graph_uri=None):
8 | super(Graph, self).__init__()
9 | self._added = set()
10 | self._removed = set()
11 |
12 | def add(self, triple):
13 | if not self.contains(triple):
14 | super(Graph, self).add(triple)
15 | self._added.add(triple)
16 |
17 | def remove(self, triple):
18 | if self.contains(triple):
19 | super(Graph, self).remove(triple)
20 | self._removed.add(triple)
21 |
22 | def changes(self, cls=Changes):
23 | return cls(added=frozenset(self._added),
24 | removed=frozenset(self._removed))
25 |
26 |
27 | class ChangeSet(object):
28 |
29 | def __init__(self, added, removed):
30 | self.added = added
31 | self.removed = removed
32 |
33 | CHANGESET_NS = "http://purl.org/vocab/changeset/schema#"
34 | NS_DICT = dict(cs=CHANGESET_NS)
35 |
36 |
37 | class CSR(Resource):
38 | namespaces = NS_DICT
39 |
40 |
41 | @register_class("cs:ChangeSet")
42 | class CS(CSR):
43 | scalars = ["cs:subjectOfChange"]
44 |
45 |
46 | @register_class("rdf:Statement")
47 | class Statement(CSR):
48 | scalars = ["rdf:subject", "rdf:predicate", "rdf:object"]
49 |
50 | @classmethod
51 | def from_triple(cls, graph, triple):
52 | statement = Statement.new(graph)
53 | statement["rdf:subject"] = triple.subject
54 | statement["rdf:predicate"] = triple.predicate
55 | statement["rdf:object"] = triple.object
56 | return statement
57 |
58 |
59 | class ChangeSetGraph(ChangeSet):
60 |
61 | def as_resource(self):
62 | change_graph = Graph()
63 | cs = CS.new(change_graph)
64 | addition_statements = set()
65 | for triple in self.added:
66 | addition_statements.add(Statement.from_triple(change_graph, triple))
67 | cs["cs:addition"] = addition_statements
68 | removal_statements = set()
69 | for triple in self.removed:
70 | removal_statements.add(Statement.from_triple(change_graph, triple))
71 | cs["cs:removal"] = removal_statements
72 | return cs
73 |
--------------------------------------------------------------------------------
/pymantic/tests/turtle_tests/test-28.out:
--------------------------------------------------------------------------------
1 | "2.345"^^ .
2 |