The Reader module contains the base class for all data and linked data readers.
Reader is the abstract class subsuming all types of file readers. There are several subtypes of readers. Each time a new reader is created, a makeLinkedData method should be created.
The read method initializes a reader by passing it a filename.
Parameter: | filename – filename string |
---|---|
Type: | string |
The LinkedDataReader module contains the LinkedDataReader class.
LinkedDataReader is a reader that is meant to process LinkedData resources, i.e., RDF+RDFS+OWL files.
then add ‘obj’ as the attribute called ‘pred’. Thus:
>>> myindiv.pred
>>> obj
addAttr also adds triples to self.kb.
Return type: | None |
---|
Return type: | None |
---|
buildPyModel iterates over all triples in Graph and converts to Python’s OOP model.
Return type: | eltk.kb.KBComponent.KBComponent |
---|
parseGraph is a wrapper around the rdflib.Graph.Graph class.
Parameters: |
|
---|---|
Return type: | rdflib.Graph.Graph |
Here’s how to create a graph object and a Python KBComponent object:
>>> reader = LinkedDataReader()
>>> GOLD_graph = reader.parseGraph(ELTK_HOME+'/examples/inputfiles/gold-2009.owl')
>>> GOLD = reader.buildPyModel()
TermsetReader is a type of Reader that processes termsets and returns Python objects.
Create a Termset object
Parameter: | uri (rdflib.URIRef.URIRef) – a uri |
---|---|
Return type: | eltk.kb.LinkedData.Termset |
Here’s how to create a termset object:
>>> myreader=TermsetReader()
>>> termset = myreader.makeLinkedData(ELTK_HOME+'/examples/inputfiles/LeipzigTermset.termset')
The LeipzigReader module is used to read a text file in Leipzig Glossing Rules format (with some additions). Here’s the expected input format:
GOLD concept name
Ethnologue15 language code
citation
comment
IGT line 1
IGT line 2
IGT line 3
See <eltk/examples/inputfiles/MorphosyntaxExamples.txt>
The reader for text in Leipzig IGT format (txt).
instantiateIGT creates instances of GOLD entities and add them to new ontology model.
Parameters: |
|
---|
Parameters: |
|
---|---|
Return type: | eltk.kb.KBComponent |
Here’s how to create IGT using the LeipzigReader. First, you need to read in the appropriate termset:
>>> termset_reader=TermsetReader()
>>> termset = termset_reader.makeLinkedData(ELTK_HOME+'/examples/inputfiles/LeipzigTermset.termset')
Next, create a reader and create some LinkedData:
>>> myreader = LeipzigReader(termset)
>>> mykb = myreader.makeLinkedData(ELTK_HOME+'/examples/inputfiles/MorphosyntaxExamples.txt')
And now you can build an RDF graph:
>>> mykb_graph = mykb.buildRDFGraph('http://purl.org/linguistics/data/LeipzigData.rdf')
>>> mykb_graph.serialize(ELTK_HOME+'/examples/outputfiles/LeipzigData.rdf')