ottr.parsers.stottr package¶
Submodules¶
ottr.parsers.stottr.lexer module¶
- 
ottr.parsers.stottr.lexer.ListOf(content: pyparsing.Group, start_char: str = '(', end_char: str = ')', separator: str = ', ') → pyparsing.Group¶
- Build a group that matches a list of the same tokens. - Args:
- content: A Group of tokens. 
- start_char: Character at the start of the the list. 
- end_char: Character at the end of the the list. 
- separator: Character used to sperate elements in the list 
 
 
- 
ottr.parsers.stottr.lexer.lex_instances_stottr(text: str) → pyparsing.Group¶
- Run the lexer on a set of stOTTR instances. - Argument: A set of stOTTR instances as text. - Returns: The lexed stOTTR instances. 
- 
ottr.parsers.stottr.lexer.lex_templates_stottr(text: str) → pyparsing.Group¶
- Run the lexer on a set of stOTTR template defintions. - Argument: A set of stOTTR template defintions as text. - Returns: The lexed stOTTR template defintions. 
ottr.parsers.stottr.parser module¶
- 
ottr.parsers.stottr.parser.get_default_nsm() → rdflib.namespace.NamespaceManager¶
- Get an rdflib NamespaceManager with default prefixes configured 
- 
ottr.parsers.stottr.parser.parse_instance_arguments(template_id: int, arguments: List[Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef, rdflib.term.Variable]], nsm: rdflib.namespace.NamespaceManager = None) → List[ottr.base.argument.InstanceArgument]¶
- Parse the arguments of a template instance. - Args:
- template_id: ID of the template. 
- arguments: instance arguments (RDF terms) to parse. 
- nsm: Namespace manager used to expand prefixed URIs. 
 
- Retuns:
- A list of instance arguments. 
 
- 
ottr.parsers.stottr.parser.parse_instances_stottr(text: str) → List[Dict[str, Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef, rdflib.term.Variable, List[Tuple[int, Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef, rdflib.term.Variable]]]]]]¶
- Parse a set of stOTTR instances and returns them as objects. - The objects returned are expected to be used with the format_arguments method of a template. - Argument: Set of stOTTR instances in text format. - Returns: A list of instances built from the valid sOTTR instances provided as input. 
- 
ottr.parsers.stottr.parser.parse_template_instance(parent_template_id: int, instance: pyparsing.Group, nsm: rdflib.namespace.NamespaceManager = None) → ottr.base.template.AbstractTemplate¶
- Parse a stOTTR template instance. - Arguments:
- parent_template_id: ID of the template that owns the scope of the instance. 
- instance: instance to parse 
- nsm: Namespace manager used to expand prefixed URIs. 
 
- Returns:
- An OTTR template. 
 
- 
ottr.parsers.stottr.parser.parse_template_parameter(template_id: int, param: pyparsing.Group, nsm: rdflib.namespace.NamespaceManager = None) → Dict[str, Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef, rdflib.term.Variable, bool]]¶
- Parse an OTTR template parameter. - Args:
- template_id: ID of the template. 
- param: Parameters to parse. 
- nsm: Namespace manager used to expand prefixed URIs. 
 
- Returns:
- A dict representation of the parsed template parameter, with fields “name” (:class`rdflib.term.Identifier`), “type” (:class`rdflib.term.URIRef`), “optional” ( - bool) and “nonblank” (- bool).
 
- 
ottr.parsers.stottr.parser.parse_templates_stottr(text: str) → List[ottr.base.template.AbstractTemplate]¶
- Parse a set of stOTTR template definitions and returns the list of all OTTR templates. - Argument: A set of stOTTR template definitions in text format. - Returns: A list of OTTR templates built from the valid sOTTR template definitions provided as input. 
- 
ottr.parsers.stottr.parser.parse_term(term: Union[str, List[str]], nsm: rdflib.namespace.NamespaceManager = None) → Union[rdflib.term.BNode, rdflib.term.Literal, rdflib.term.URIRef, rdflib.term.Variable]¶
- Parse a raw RDF term or a list of raw RDF Terms into the rdflib format. - Args:
- term: (List of) RDF Term(s) to parse (in n-triples format). 
- nsm: Namespace manager used to expand prefixed URIs. 
 
- Returns:
- The parsed RDF term in rdflib format. 
 
- 
ottr.parsers.stottr.parser.unify_var(variable: rdflib.term.Variable, suffix: Union[str, int]) → rdflib.term.Variable¶
- Makes a SPARQL Variable unique by appending a suffix to it. - Args:
- value: Variable to make unique. 
- suffix: suffix to append at the end of the value. 
 
- Returns:
- A new SPARQL Variable