1
+ """
2
+ The module provides access to QueryParser and QueryCreator classes.
3
+ QueryParsers parse search strings to odml query dictionaries that can be
4
+ consumed by QueryCreators. QueryCreators create RDF queries from
5
+ provided odml query dictionaries.
6
+ """
7
+
1
8
import re
2
9
from abc import ABCMeta , abstractmethod
3
10
10
17
11
18
12
19
class BaseQueryCreator :
20
+ """
21
+ An abstract base class for odml specific QueryCreators.
22
+ """
13
23
14
24
__metaclass__ = ABCMeta
15
25
@@ -28,6 +38,13 @@ def __init__(self, q_dict=None):
28
38
29
39
@abstractmethod
30
40
def get_query (self , q_str , q_parser ):
41
+ """
42
+ Construct a SPARQL query from an input string.
43
+
44
+ :param q_str: input string.
45
+ :param q_parser: parser to use on the input string.
46
+ :return SPARQL query.
47
+ """
31
48
pass
32
49
33
50
@abstractmethod
@@ -36,6 +53,9 @@ def _prepare_query(self):
36
53
37
54
38
55
class BaseQueryParser :
56
+ """
57
+ An abstract base class for QueryParsers.
58
+ """
39
59
40
60
__metaclass__ = ABCMeta
41
61
@@ -44,17 +64,27 @@ def __init__(self):
44
64
45
65
@abstractmethod
46
66
def parse_query_string (self , q_str ):
67
+ """
68
+ Parse an input string and return a dictionary consumable by a QueryCreator.
69
+ """
47
70
pass
48
71
49
72
50
73
class QueryParserFuzzy (BaseQueryParser ):
74
+ """
75
+ This class parses an odml specific input string and uses
76
+ heuristics to approximate which Section or Property attributes
77
+ should be matched against multiple search parameters and constructs
78
+ an odml specific SPARQL query.
79
+ """
51
80
52
81
def __init__ (self ):
53
82
super (QueryParserFuzzy , self ).__init__ ()
54
83
55
84
def parse_query_string (self , q_str ):
56
85
"""
57
86
Parse query string and returns dict object with parameters.
87
+
58
88
:param q_str: query string.
59
89
Example: FIND sec(name, type) prop(type) HAVING Stimulus, Contrast
60
90
:return: dict object.
@@ -143,6 +173,9 @@ def _parse_having(self, having_part):
143
173
144
174
145
175
class QueryParser (BaseQueryParser ):
176
+ """
177
+ This class parses an odml specific input string into an odml specific SPARQL query.
178
+ """
146
179
147
180
def __init__ (self ):
148
181
super (QueryParser , self ).__init__ ()
@@ -228,7 +261,7 @@ def get_query(self, q_str=None, q_parser=None):
228
261
:param q_parser: one of possible query parsers.
229
262
:param q_str: doc(author:D. N. Adams) section(name:Stimulus)
230
263
prop(name:Contrast, value:20, unit:%)
231
- :return rdflib prepare query.
264
+ :return rdflib prepared query.
232
265
"""
233
266
if not self .q_dict :
234
267
if not q_str :
@@ -244,6 +277,7 @@ def get_query(self, q_str=None, q_parser=None):
244
277
def _prepare_query (self ):
245
278
"""
246
279
Creates rdflib query using parameters from self.q_dict.
280
+
247
281
:return: string representing rdflib query.
248
282
"""
249
283
0 commit comments