Table Of Contents

Previous topic

Termset

Next topic

Data Display

This Page

Readers

The Reader module contains the base class for all data and linked data readers.

class eltk.reader.Reader.Reader

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.

read(filename)

The read method initializes a reader by passing it a filename.

Parameter:filename – filename string
Type:string

LinkedDataReader

The LinkedDataReader module contains the LinkedDataReader class.

class eltk.reader.LinkedDataReader.LinkedDataReader

LinkedDataReader is a reader that is meant to process LinkedData resources, i.e., RDF+RDFS+OWL files.

addAttr()
addAttr adds attributes to individuals. If the RDF graph contains:
myindiv –pred–> obj

then add ‘obj’ as the attribute called ‘pred’. Thus:

>>> myindiv.pred
>>> obj

addAttr also adds triples to self.kb.

Return type:None
addFunc()
addFunc attaches various useful instance methods to each kb attribute:
  • a function that returns all subclasses
  • a function that returns all instances
Return type:None
buildPyModel()

buildPyModel iterates over all triples in Graph and converts to Python’s OOP model.

Return type:eltk.kb.KBComponent.KBComponent
parseGraph(inputfile, identifier='')

parseGraph is a wrapper around the rdflib.Graph.Graph class.

Parameters:
  • inputfile (str) – An input file location
  • indentifier (rdflib.URIRef.URIRef) – An identifier for the resource, can be null.
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

class eltk.reader.TermsetReader.TermsetReader

TermsetReader is a type of Reader that processes termsets and returns Python objects.

makeLinkedData(filename, ns='http://purl.org/linguistics/data/')

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')

LeipzigReader

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>

class eltk.reader.LeipzigReader.LeipzigReader(termset=None)

The reader for text in Leipzig IGT format (txt).

instantiateIGT(new_id, lang, source, gloss, translation)

instantiateIGT creates instances of GOLD entities and add them to new ontology model.

Parameters:
  • new_ID – a random id string
  • land – a 3 letter code
  • source (list) – a list of strings from line 1 of IGT
  • gloss (list) – a list of glossed from line 2 of IGT
  • translation (str) – a translation from line 3 of IGT
makeLinkedData(filename, ns='http://purl.org/linguistics/data/')
Parameters:
  • filename (str) – a filename string
  • ns (str) – a namespace string
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')