Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/rdflib/__init__.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 """A pure Python package providing the core RDF constructs. | |
| 2 | |
| 3 The packages is intended to provide the core RDF types and interfaces | |
| 4 for working with RDF. The package defines a plugin interface for | |
| 5 parsers, stores, and serializers that other packages can use to | |
| 6 implement parsers, stores, and serializers that will plug into the | |
| 7 rdflib package. | |
| 8 | |
| 9 The primary interface `rdflib` exposes to work with RDF is | |
| 10 `rdflib.graph.Graph`. | |
| 11 | |
| 12 A tiny example: | |
| 13 | |
| 14 >>> from rdflib import Graph, URIRef, Literal | |
| 15 | |
| 16 >>> g = Graph() | |
| 17 >>> result = g.parse("http://www.w3.org/2000/10/swap/test/meet/blue.rdf") | |
| 18 | |
| 19 >>> print("graph has %s statements." % len(g)) | |
| 20 graph has 4 statements. | |
| 21 >>> | |
| 22 >>> for s, p, o in g: | |
| 23 ... if (s, p, o) not in g: | |
| 24 ... raise Exception("It better be!") | |
| 25 | |
| 26 >>> s = g.serialize(format='nt') | |
| 27 >>> | |
| 28 >>> sorted(g) == [ | |
| 29 ... (URIRef(u'http://meetings.example.com/cal#m1'), | |
| 30 ... URIRef(u'http://www.example.org/meeting_organization#homePage'), | |
| 31 ... URIRef(u'http://meetings.example.com/m1/hp')), | |
| 32 ... (URIRef(u'http://www.example.org/people#fred'), | |
| 33 ... URIRef(u'http://www.example.org/meeting_organization#attending'), | |
| 34 ... URIRef(u'http://meetings.example.com/cal#m1')), | |
| 35 ... (URIRef(u'http://www.example.org/people#fred'), | |
| 36 ... URIRef(u'http://www.example.org/personal_details#GivenName'), | |
| 37 ... Literal(u'Fred')), | |
| 38 ... (URIRef(u'http://www.example.org/people#fred'), | |
| 39 ... URIRef(u'http://www.example.org/personal_details#hasEmail'), | |
| 40 ... URIRef(u'mailto:fred@example.com')) | |
| 41 ... ] | |
| 42 True | |
| 43 | |
| 44 """ | |
| 45 __docformat__ = "restructuredtext en" | |
| 46 | |
| 47 # The format of the __version__ line is matched by a regex in setup.py | |
| 48 __version__ = "4.2.2" | |
| 49 __date__ = "2017/01/29" | |
| 50 | |
| 51 __all__ = [ | |
| 52 'URIRef', | |
| 53 'BNode', | |
| 54 'Literal', | |
| 55 'Variable', | |
| 56 | |
| 57 'Namespace', | |
| 58 | |
| 59 'Dataset', | |
| 60 'Graph', | |
| 61 'ConjunctiveGraph', | |
| 62 | |
| 63 'RDF', | |
| 64 'RDFS', | |
| 65 'OWL', | |
| 66 'XSD', | |
| 67 | |
| 68 'util', | |
| 69 ] | |
| 70 | |
| 71 import sys | |
| 72 assert sys.version_info >= (2, 5, 0), "rdflib requires Python 2.5 or higher" | |
| 73 | |
| 74 import logging | |
| 75 _interactive_mode = False | |
| 76 try: | |
| 77 import __main__ | |
| 78 if not hasattr(__main__, '__file__') and sys.stdout.isatty(): | |
| 79 # show log messages in interactive mode | |
| 80 _interactive_mode = True | |
| 81 logging.basicConfig(level=logging.INFO) | |
| 82 del __main__ | |
| 83 except ImportError: | |
| 84 #Main already imported from elsewhere | |
| 85 import warnings | |
| 86 warnings.warn('__main__ already imported', ImportWarning) | |
| 87 del warnings | |
| 88 | |
| 89 logger = logging.getLogger(__name__) | |
| 90 if _interactive_mode: | |
| 91 logger.info("RDFLib Version: %s" % __version__) | |
| 92 else: | |
| 93 logger.debug("RDFLib Version: %s" % __version__) | |
| 94 del _interactive_mode | |
| 95 del sys | |
| 96 | |
| 97 | |
| 98 try: | |
| 99 chr(0x10FFFF) | |
| 100 except ValueError: | |
| 101 import warnings | |
| 102 warnings.warn( | |
| 103 'You are using a narrow Python build!\n' | |
| 104 'This means that your Python does not properly support chars > 16bit.\n' | |
| 105 'On your system chars like c=u"\\U0010FFFF" will have a len(c)==2.\n' | |
| 106 'As this can cause hard to debug problems with string processing\n' | |
| 107 '(slicing, regexp, ...) later on, we strongly advise to use a wide\n' | |
| 108 'Python build in production systems.', | |
| 109 ImportWarning) | |
| 110 del warnings | |
| 111 | |
| 112 | |
| 113 NORMALIZE_LITERALS = True | |
| 114 """ | |
| 115 If True - Literals lexical forms are normalized when created. | |
| 116 I.e. the lexical forms is parsed according to data-type, then the | |
| 117 stored lexical form is the re-serialized value that was parsed. | |
| 118 | |
| 119 Illegal values for a datatype are simply kept. The normalized keyword | |
| 120 for Literal.__new__ can override this. | |
| 121 | |
| 122 For example: | |
| 123 | |
| 124 >>> from rdflib import Literal,XSD | |
| 125 >>> Literal("01", datatype=XSD.int) | |
| 126 rdflib.term.Literal(u'1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer')) | |
| 127 | |
| 128 This flag may be changed at any time, but will only affect literals | |
| 129 created after that time, previously created literals will remain | |
| 130 (un)normalized. | |
| 131 | |
| 132 """ | |
| 133 | |
| 134 | |
| 135 DAWG_LITERAL_COLLATION = False | |
| 136 """ | |
| 137 DAWG_LITERAL_COLLATION determines how literals are ordered or compared | |
| 138 to each other. | |
| 139 | |
| 140 In SPARQL, applying the >,<,>=,<= operators to literals of | |
| 141 incompatible data-types is an error, i.e: | |
| 142 | |
| 143 Literal(2)>Literal('cake') is neither true nor false, but an error. | |
| 144 | |
| 145 This is a problem in PY3, where lists of Literals of incompatible | |
| 146 types can no longer be sorted. | |
| 147 | |
| 148 Setting this flag to True gives you strict DAWG/SPARQL compliance, | |
| 149 setting it to False will order Literals with incompatible datatypes by | |
| 150 datatype URI | |
| 151 | |
| 152 In particular, this determines how the rich comparison operators for | |
| 153 Literal work, eq, __neq__, __lt__, etc. | |
| 154 """ | |
| 155 | |
| 156 from rdflib.term import ( | |
| 157 URIRef, BNode, Literal, Variable) | |
| 158 | |
| 159 from rdflib.namespace import Namespace | |
| 160 | |
| 161 from rdflib.graph import Dataset, Graph, ConjunctiveGraph | |
| 162 | |
| 163 from rdflib.namespace import RDF, RDFS, OWL, XSD | |
| 164 | |
| 165 from rdflib import plugin | |
| 166 from rdflib import query | |
| 167 # tedious sop to flake8 | |
| 168 assert plugin | |
| 169 assert query | |
| 170 | |
| 171 from rdflib import util |
