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+
18import re
29from abc import ABCMeta , abstractmethod
310
1017
1118
1219class BaseQueryCreator :
20+ """
21+ An abstract base class for odml specific QueryCreators.
22+ """
1323
1424 __metaclass__ = ABCMeta
1525
@@ -28,6 +38,13 @@ def __init__(self, q_dict=None):
2838
2939 @abstractmethod
3040 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+ """
3148 pass
3249
3350 @abstractmethod
@@ -36,6 +53,9 @@ def _prepare_query(self):
3653
3754
3855class BaseQueryParser :
56+ """
57+ An abstract base class for QueryParsers.
58+ """
3959
4060 __metaclass__ = ABCMeta
4161
@@ -44,17 +64,27 @@ def __init__(self):
4464
4565 @abstractmethod
4666 def parse_query_string (self , q_str ):
67+ """
68+ Parse an input string and return a dictionary consumable by a QueryCreator.
69+ """
4770 pass
4871
4972
5073class 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+ """
5180
5281 def __init__ (self ):
5382 super (QueryParserFuzzy , self ).__init__ ()
5483
5584 def parse_query_string (self , q_str ):
5685 """
5786 Parse query string and returns dict object with parameters.
87+
5888 :param q_str: query string.
5989 Example: FIND sec(name, type) prop(type) HAVING Stimulus, Contrast
6090 :return: dict object.
@@ -143,6 +173,9 @@ def _parse_having(self, having_part):
143173
144174
145175class QueryParser (BaseQueryParser ):
176+ """
177+ This class parses an odml specific input string into an odml specific SPARQL query.
178+ """
146179
147180 def __init__ (self ):
148181 super (QueryParser , self ).__init__ ()
@@ -228,7 +261,7 @@ def get_query(self, q_str=None, q_parser=None):
228261 :param q_parser: one of possible query parsers.
229262 :param q_str: doc(author:D. N. Adams) section(name:Stimulus)
230263 prop(name:Contrast, value:20, unit:%)
231- :return rdflib prepare query.
264+ :return rdflib prepared query.
232265 """
233266 if not self .q_dict :
234267 if not q_str :
@@ -244,6 +277,7 @@ def get_query(self, q_str=None, q_parser=None):
244277 def _prepare_query (self ):
245278 """
246279 Creates rdflib query using parameters from self.q_dict.
280+
247281 :return: string representing rdflib query.
248282 """
249283
0 commit comments