Skip to content

Commit 3a88290

Browse files
committed
more pythonic naming for various imported functions WIP
1 parent 719659a commit 3a88290

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

rdflib_sqlalchemy/store.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from rdflib import (
1010
BNode,
1111
Literal,
12-
RDF,
1312
URIRef
1413
)
1514
from rdflib.graph import Graph, QuotedGraph
15+
from rdflib.namespace import RDF
1616
from rdflib.plugins.stores.regexmatching import PYTHON_REGEX, REGEXTerm
1717
from rdflib.store import Store
1818
from six import text_type
@@ -23,19 +23,19 @@
2323

2424
from rdflib_sqlalchemy import __version__
2525
from rdflib_sqlalchemy.tables import (
26+
TABLE_NAME_TEMPLATES,
2627
create_asserted_statements_table,
2728
create_literal_statements_table,
2829
create_namespace_binds_table,
2930
create_quoted_statements_table,
3031
create_type_statements_table,
31-
TABLE_NAME_TEMPLATES,
3232
)
3333
from rdflib_sqlalchemy.termutils import (
3434
REVERSE_TERM_COMBINATIONS,
3535
TERM_INSTANTIATION_DICT,
36-
constructGraph,
37-
type2TermCombination,
38-
statement2TermCombination,
36+
construct_graph,
37+
type_to_term_combination,
38+
statement_to_term_combination,
3939
)
4040

4141

@@ -199,7 +199,7 @@ def extractTriple(tupleRt, store, hardCodedContext=None):
199199
p = createTerm(predicate, predTerm, store)
200200
o = createTerm(obj, objTerm, store, objLanguage, objDatatype)
201201

202-
graphKlass, idKlass = constructGraph(ctxTerm)
202+
graphKlass, idKlass = construct_graph(ctxTerm)
203203
if __version__ <= "0.2":
204204
return s, p, o, (graphKlass, idKlass, context)
205205
else:
@@ -289,7 +289,7 @@ def _build_type_sql_command(self, member, klass, context):
289289
"member": member,
290290
"klass": klass,
291291
"context": context.identifier,
292-
"termComb": int(type2TermCombination(member, klass, context))}
292+
"termComb": int(type_to_term_combination(member, klass, context))}
293293

294294
def _build_literal_triple_sql_command(self, subject, predicate, obj, context):
295295
"""
@@ -298,7 +298,7 @@ def _build_literal_triple_sql_command(self, subject, predicate, obj, context):
298298
(Statements where the object is a Literal).
299299
"""
300300
triple_pattern = int(
301-
statement2TermCombination(subject, predicate, obj, context)
301+
statement_to_term_combination(subject, predicate, obj, context)
302302
)
303303
command = self.tables["literal_statements"].insert()
304304
values = {
@@ -321,8 +321,12 @@ def _build_triple_sql_command(self, subject, predicate, obj, context, quoted):
321321
self.tables["quoted_statements"] or
322322
self.tables["asserted_statements"])
323323

324-
triple_pattern = statement2TermCombination(
325-
subject, predicate, obj, context)
324+
triple_pattern = statement_to_term_combination(
325+
subject,
326+
predicate,
327+
obj,
328+
context,
329+
)
326330
command = stmt_table.insert()
327331

328332
if quoted:

rdflib_sqlalchemy/termutils.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
__all__ = ["SUBJECT", "PREDICATE", "OBJECT", "CONTEXT", "TERM_COMBINATIONS",
1313
"REVERSE_TERM_COMBINATIONS", "TERM_INSTANTIATION_DICT",
14-
"GRAPH_TERM_DICT", "normalizeGraph", "term2Letter",
15-
"constructGraph", "triplePattern2termCombinations",
16-
"type2TermCombination", "statement2TermCombination",
14+
"GRAPH_TERM_DICT", "normalizeGraph", "term_to_letter",
15+
"construct_graph", "triplePattern2termCombinations",
16+
"type_to_term_combination", "statement_to_term_combination",
1717
"escape_quotes"]
1818

1919
SUBJECT = 0
@@ -98,11 +98,11 @@ def normalizeGraph(graph):
9898
if isinstance(graph, QuotedGraph):
9999
return graph.identifier, "F"
100100
else:
101-
return graph.identifier, term2Letter(graph.identifier)
101+
return graph.identifier, term_to_letter(graph.identifier)
102102

103103

104104
@format_doctest_out
105-
def term2Letter(term):
105+
def term_to_letter(term):
106106
"""
107107
Relate a given term to one of several key types.
108108
@@ -118,22 +118,22 @@ def term2Letter(term):
118118
>>> from rdflib.term import BNode
119119
>>> # from rdflib.term import Statement
120120
>>> from rdflib.graph import Graph, QuotedGraph
121-
>>> from rdflib_sqlalchemy.termutils import term2Letter
122-
>>> term2Letter(URIRef('http://purl.org/net/bel-epa.com/'))
121+
>>> from rdflib_sqlalchemy.termutils import term_to_letter
122+
>>> term_to_letter(URIRef('http://purl.org/net/bel-epa.com/'))
123123
'U'
124-
>>> term2Letter(BNode())
124+
>>> term_to_letter(BNode())
125125
'B'
126-
>>> term2Letter(Literal(%(u)s'')) # noqa
126+
>>> term_to_letter(Literal(%(u)s'')) # noqa
127127
'L'
128-
>>> term2Letter(Variable(%(u)s'x')) # noqa
128+
>>> term_to_letter(Variable(%(u)s'x')) # noqa
129129
'V'
130-
>>> term2Letter(Graph())
130+
>>> term_to_letter(Graph())
131131
'B'
132-
>>> term2Letter(QuotedGraph("IOMemory", None))
132+
>>> term_to_letter(QuotedGraph("IOMemory", None))
133133
'F'
134-
>>> term2Letter(None)
134+
>>> term_to_letter(None)
135135
'L'
136-
>>> # term2Letter(Statement((None, None, None), None)) # Deprecated
136+
>>> # term_to_letter(Statement((None, None, None), None)) # Deprecated
137137
138138
"""
139139
if isinstance(term, URIRef):
@@ -149,7 +149,7 @@ def term2Letter(term):
149149
elif isinstance(term, Statement):
150150
return "s"
151151
elif isinstance(term, Graph):
152-
return term2Letter(term.identifier)
152+
return term_to_letter(term.identifier)
153153
elif term is None:
154154
return "L"
155155
else:
@@ -160,18 +160,18 @@ def term2Letter(term):
160160
% (term, type(term)))
161161

162162

163-
def constructGraph(key):
163+
def construct_graph(key):
164164
"""
165165
Return a tuple containing a ``Graph`` and an appropriate referent.
166166
167167
Takes a key (one of 'F', 'U' or 'B')
168168
169-
>>> from rdflib_sqlalchemy.termutils import constructGraph
170-
>>> constructGraph('F')
169+
>>> from rdflib_sqlalchemy.termutils import construct_graph
170+
>>> construct_graph('F')
171171
(<class 'rdflib.graph.QuotedGraph'>, <class 'rdflib.term.URIRef'>)
172-
>>> constructGraph('U')
172+
>>> construct_graph('U')
173173
(<class 'rdflib.graph.Graph'>, <class 'rdflib.term.URIRef'>)
174-
>>> constructGraph('B')
174+
>>> construct_graph('B')
175175
(<class 'rdflib.graph.Graph'>, <class 'rdflib.term.BNode'>)
176176
177177
"""
@@ -190,12 +190,12 @@ def triplePattern2termCombinations(triple):
190190
return combinations
191191

192192

193-
def type2TermCombination(member, klass, context):
193+
def type_to_term_combination(member, klass, context):
194194
"""Map a type to a TermCombo."""
195195
try:
196196
rt = TERM_COMBINATIONS["%sU%s%s" %
197-
(term2Letter(member),
198-
term2Letter(klass),
197+
(term_to_letter(member),
198+
term_to_letter(klass),
199199
normalizeGraph(context)[-1])]
200200
return rt
201201
except:
@@ -204,11 +204,11 @@ def type2TermCombination(member, klass, context):
204204
(member, "rdf:type", klass, context))
205205

206206

207-
def statement2TermCombination(subject, predicate, obj, context):
207+
def statement_to_term_combination(subject, predicate, obj, context):
208208
"""Map a statement to a Term Combo."""
209209
return TERM_COMBINATIONS["%s%s%s%s" %
210-
(term2Letter(subject), term2Letter(predicate),
211-
term2Letter(obj), normalizeGraph(context)[-1])]
210+
(term_to_letter(subject), term_to_letter(predicate),
211+
term_to_letter(obj), normalizeGraph(context)[-1])]
212212

213213

214214
def escape_quotes(qstr):

0 commit comments

Comments
 (0)