Skip to content

Commit

Permalink
Merge pull request #27 from Capitains/dev
Browse files Browse the repository at this point in the history
Implementation of passages architecture for local.
  • Loading branch information
PonteIneptique committed Jul 17, 2015
2 parents 79e1871 + 8ffe59e commit 967fa33
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 56 deletions.
12 changes: 12 additions & 0 deletions MyCapytain/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
from lxml import etree
from io import IOBase, StringIO
from past.builtins import basestring
import re

__strip = re.compile("([ ]{2,})+")
def normalize(string):
""" Remove double-or-more spaces in a string
:param string: A string to change
:type string: basestring
:rtype: Basestring
:returns: Clean string
"""
return __strip.sub(" ", string)

#: Dictionary of namespace that can be useful
NS = {
Expand Down
65 changes: 60 additions & 5 deletions MyCapytain/resources/proto/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

from MyCapytain.resources.proto import inventory
import MyCapytain.common.reference
from collections import namedtuple

PassagePlus = namedtuple("PassagePlus", ["passage", "prev", "next"])

class Resource(object):
""" Initiate a Resource object
Expand Down Expand Up @@ -57,21 +60,73 @@ def urn(self, value):


class Passage(Resource):
""" Passage representing object prototype
:param urn: A URN identifier
:type urn: MyCapytain.common.reference.URN
:param resource: A resource
:type resource: lxml.etree._Element
:param parent: Parent of the current passage
:type parent: MyCapytain.resources.texts.tei.Passage
:param citation: Citation for children level
:type citation: MyCapytain.resources.texts.tei.Citation
:param id: Identifier of the subreference without URN informations
:type id: List
"""

def __init__(self, parent=None, **kwargs):
super(Passage, self).__init__(**kwargs)
self.parent = None
if parent is not None and isinstance(parent, Passage):
self.parent = parent

@property
def prev(self):
""" Previous passage
:rtype: Passage
:returns: Previous passage at same level
"""
raise NotImplementedError()

def setText(self):
@property
def next(self):
""" Following passage
:rtype: Passage
:returns: Following passage at same level
"""
raise NotImplementedError()

def getText(self):
@property
def first(self):
""" First child of current Passage
:rtype: None or Passage
:returns: None if current Passage has no children, first child passage if available
"""
raise NotImplementedError()

def getNext(self):
@property
def last(self):
""" Last child of current Passage
:rtype: None or Passage
:returns: None if current Passage has no children, last child passage if available
"""
raise NotImplementedError()

def getPrev(self):
@property
def children(self):
""" Children of the passage
:rtype: OrderedDict
:returns: Dictionary of chidren, where key are subreferences
"""
raise NotImplementedError()


class Text(Resource):
""" A CTS Text """
def __init__(self, citation=None, **kwargs):
Expand All @@ -82,7 +137,7 @@ def __init__(self, citation=None, **kwargs):
if citation is not None:
self.citation = citation

def getValidReff(self, level=1, passage=None):
def getValidReff(self, level=1, reference=None):
""" Given a resource, Text will compute valid reffs
:param level: Depth required. If not set, should retrieve first encountered level (1 based)
Expand Down

0 comments on commit 967fa33

Please sign in to comment.