示例#1
0
from rdfalchemy import Namespace
from rdfalchemy.Literal import Literal
from datetime import datetime
from decimal import Decimal
# from rdflib.term import bind as bindLiteral

import logging
log = logging.getLogger()
if not log.handlers:
    log.addHandler(logging.StreamHandler())
#log.setLevel(10)

XSD = Namespace(u'http://www.w3.org/2001/XMLSchema#')


def just_for_coverage_test():
    from rdfalchemy.Literal import _strToDateTime
    x = _strToDateTime('2008-02-09T10:46:29')
    assert type(x) == datetime


def toPython_decimal_test():
    """docstring for toPython"""
    # test a normal iso
    d = Literal('.1', datatype=XSD.decimal).toPython()
    assert isinstance(d, Decimal)
    payments = [
        Literal(s, datatype=XSD.decimal) for s in '.1 .1 .1 -.3'.split()
    ]
    assert sum([payment.toPython() for payment in payments]) == 0
示例#2
0
from rdfalchemy import (rdfSubject, RDF, RDFS, Namespace, BNode, URIRef)
from rdflib.py3compat import PY3
from rdflib.term import Identifier
from descriptors import (rdfSingle, rdfMultiple, owlTransitive)
from orm import mapper, allsub

import logging
log = logging.getLogger(__name__)
#log.debug("logger is %s",log.name)
log.setLevel(logging.INFO)

from weakref import WeakValueDictionary
import re

OWL = Namespace("http://www.w3.org/2002/07/owl#")

_all_ = [
    'rdfsSubject', 'rdfsClass', 'rdfsProperty', 'owlObjectProperty',
    'owlDatatypeProperty', 'owlSymetricProperty', 'owlTransitiveProperty',
    'owlFunctionalProperty', 'owlInverseFunctionalProperty'
]

re_ns_n = re.compile(r'(.*[/#])(.*)')


class rdfsSubject(rdfSubject, Identifier):
    _weakrefs = WeakValueDictionary()

    def __new__(cls, resUri=None, schemaGraph=None, *args, **kwargs):
        #  create a bnode
示例#3
0
from __future__ import print_function
from rdfalchemy import (Namespace, rdfSingle, rdfMultiple)
from rdfalchemy.rdfsSubject import rdfsSubject

DC = Namespace('http://purl.org/dc/terms/')
BIBO = Namespace('http://purl.org/ontology/bibo/')
FOAF = Namespace('http://xmlns.com/foaf/0.1/')
SKOS = Namespace('http://www.w3.org/2004/02/skos/core#')


class Document(rdfsSubject):
    rdf_type = BIBO.Document
    title = rdfSingle(DC['title'])
    alt_titles = rdfMultiple(DC.alt)
    date = rdfSingle(DC.date)
    issued = rdfSingle(DC.issued)
    modified = rdfSingle(DC.modified)
    creators = rdfMultiple(DC.creator)
    authorList = rdfMultiple(BIBO.authorList)
    subjects = rdfMultiple(DC.subject, range_type=SKOS.Concept)


class Book(Document):
    rdf_type = BIBO.Book
    publisher = rdfSingle(DC.publisher, range_type=FOAF.Organization)
    series = rdfSingle(DC.isPartOf, range_type=BIBO.Series)


x = Book(title="Some Title")
y = Document(title="Another Title")