Skip to content

Commit

Permalink
Some more code
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Dec 1, 2016
1 parent 98e9d97 commit 9735b79
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 18 deletions.
65 changes: 65 additions & 0 deletions MyCapytain/resolvers/cts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from MyCapytain.resolvers.prototypes import Resolver
from MyCapytain.resources.texts.api.cts import Text, Passage
from MyCapytain.retrievers.cts5 import CTS


class HttpCTSResolver(Resolver):
def __init__(self, endpoint):
if not isinstance(endpoint, CTS):
raise TypeError("Endpoint should be a CTS Endpoint object")
self.__endpoint__ = endpoint

@property
def endpoint(self):
""" CTS Endpoint of the resolver
:return: CTS Endpoint
:rtype: CTS
"""
return self.__endpoint__

def getPassage(self, textId, subreference=None, prevnext=False, metadata=False):
""" Retrieve a text node from the API
:param textId: Text Identifier
:param subreference: Passage Reference
:param prevnext: Retrieve graph representing previous and next passage
:param metadata: Retrieve metadata about the passage and the text
:return: Passage
:rtype: Passage
"""
text = Text(
urn=textId,
retriever=self.endpoint
)
if metadata or prevnext:
return text.getPassagePlus(reference=subreference)
else:
return text.getPassage(reference=subreference)

def getSiblings(self, textId, subreference):
""" Retrieve the siblings of a textual node
:param textId: Text Identifier
:param subreference: Passage Reference
:return: (str, str)
"""
text = Text(
urn=textId,
retriever=self.endpoint
)
return text.getPrevNextUrn(subreference)

def getSiblings(self, textId, subreference):
""" Retrieve the siblings of a textual node
:param textId: Text Identifier
:param subreference: Passage Reference
:return: (str, str)
"""
text = Text(
urn=textId,
retriever=self.endpoint
)
return text.getPrevNextUrn(subreference)

22 changes: 10 additions & 12 deletions MyCapytain/resolvers/prototypes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



class Resolver(object):
def getMetadata(self, objectId=None, **filters):
""" Request metadata about a text or a collection
Expand All @@ -11,25 +8,26 @@ def getMetadata(self, objectId=None, **filters):
"""
raise NotImplementedError

def getText(self, textId, reference=None, prevnext=False, metadata=False):
def getPassage(self, textId, subreference=None, prevnext=False, metadata=False):
""" Retrieve a text node from the API
:param textId: Text Identifier
:param reference: Passage Reference
:param subreference: Passage Reference
:param prevnext: Retrieve graph representing previous and next passage
:param metadata: Retrieve metadata about the passage and the text
:return: Text of a Passage from an API or the likes as bytes
:return: Passage
:rtype: Passage
"""
raise NotImplementedError
raise NotImplementedError()

def getSiblings(self, textId, reference):
def getSiblings(self, textId, subreference):
""" Retrieve the siblings of a textual node
:param textId: Text Identifier
:param reference: Passage Reference
:return: Graph
:param subreference: Passage Reference
:return: (str, str)
"""
raise NotImplementedError
raise NotImplementedError()

def getChildren(self, textId, reference=None, depth=None):
""" Retrieve the siblings of a textual node
Expand All @@ -38,4 +36,4 @@ def getChildren(self, textId, reference=None, depth=None):
:param reference: Passage Reference
:return: Graph
"""
raise NotImplementedError
raise NotImplementedError()
Binary file modified classes_MyCapytain.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages_MyCapytain.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requests>=2.8.1
lxml==3.6.4
mock==1.3.0
future==0.15.2
lxml>=3.6.4
mock>=2.0.0
future>=0.16.0
six>=1.10.0
xmlunittest>=0.3.2
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
install_requires=[
"requests>=2.8.1",
"six>=1.10.0",
"lxml==3.6.4",
"future==0.15.2"
"lxml>=3.6.4",
"future>=0.16.0"
],
tests_require=[
"mock==1.3.0",
"mock>=2.0.0",
"xmlunittest>=0.3.2"
],
extras_require={
Expand Down

0 comments on commit 9735b79

Please sign in to comment.