@@ -48,8 +48,15 @@ class CopyvioCheckResult(object): | |||||
self.delta_chain = chains[1] | self.delta_chain = chains[1] | ||||
def __repr__(self): | def __repr__(self): | ||||
r = "CopyvioCheckResult(violation={0!r}, confidence={1!r}, url={2!r}, queries={3|r})" | |||||
return r.format(self.violation, self.confidence, self.url, self.queries) | |||||
"""Return the canonical string representation of the result.""" | |||||
res = "CopyvioCheckResult(violation={0!r}, confidence={1!r}, url={2!r}, queries={3|r})" | |||||
return res.format(self.violation, self.confidence, self.url, | |||||
self.queries) | |||||
def __str__(self): | |||||
"""Return a nice string representation of the result.""" | |||||
res = "<CopyvioCheckResult ({0} with {1} conf)>" | |||||
return res.format(self.violation, self.confidence) | |||||
class CopyvioMixIn(object): | class CopyvioMixIn(object): | ||||
@@ -42,6 +42,14 @@ class MarkovChain(object): | |||||
except KeyError: | except KeyError: | ||||
pass | pass | ||||
def __repr__(self): | |||||
"""Return the canonical string representation of the MarkovChain.""" | |||||
return "MarkovChain(text={0!r})".format(self.text) | |||||
def __str__(self): | |||||
"""Return a nice string representation of the MarkovChain.""" | |||||
return "<MarkovChain of size {0}>".format(self.size()) | |||||
def size(self): | def size(self): | ||||
count = 0 | count = 0 | ||||
for node in self.chain.itervalues(): | for node in self.chain.itervalues(): | ||||
@@ -53,6 +61,7 @@ class MarkovChain(object): | |||||
class MarkovChainIntersection(MarkovChain): | class MarkovChainIntersection(MarkovChain): | ||||
def __init__(self, mc1, mc2): | def __init__(self, mc1, mc2): | ||||
self.chain = defaultdict(lambda: defaultdict(lambda: 0)) | self.chain = defaultdict(lambda: defaultdict(lambda: 0)) | ||||
self.mc1, self.mc2 = mc1, mc2 | |||||
c1 = mc1.chain | c1 = mc1.chain | ||||
c2 = mc2.chain | c2 = mc2.chain | ||||
@@ -63,3 +72,13 @@ class MarkovChainIntersection(MarkovChain): | |||||
if node in nodes2: | if node in nodes2: | ||||
count2 = nodes2[node] | count2 = nodes2[node] | ||||
self.chain[word][node] = min(count1, count2) | self.chain[word][node] = min(count1, count2) | ||||
def __repr__(self): | |||||
"""Return the canonical string representation of the intersection.""" | |||||
res = "MarkovChainIntersection(mc1={0!r}, mc2={1!r})" | |||||
return res.format(self.mc1, self.mc2) | |||||
def __str__(self): | |||||
"""Return a nice string representation of the intersection.""" | |||||
res = "<MarkovChainIntersection of size {0} ({1} ^ {2})>" | |||||
return res.format(self.size(), self.mc1, self.mc2) |
@@ -23,6 +23,15 @@ | |||||
__all__ = ["BaseTextParser", "ArticleTextParser", "HTMLTextParser"] | __all__ = ["BaseTextParser", "ArticleTextParser", "HTMLTextParser"] | ||||
class BaseTextParser(object): | class BaseTextParser(object): | ||||
def __repr__(self): | |||||
"""Return the canonical string representation of the text parser.""" | |||||
return "{0}(text={1!r})".format(self.__class__.__name__, self.text) | |||||
def __str__(self): | |||||
"""Return a nice string representation of the text parser.""" | |||||
name = self.__class__.__name__ | |||||
return "<{0} of text with size {1}>".format(name, len(text)) | |||||
def __init__(self, text): | def __init__(self, text): | ||||
self.text = text | self.text = text | ||||
@@ -37,6 +37,14 @@ class BaseSearchEngine(object): | |||||
"""Store credentials 'cred' for searching later on.""" | """Store credentials 'cred' for searching later on.""" | ||||
self.cred = cred | self.cred = cred | ||||
def __repr__(self): | |||||
"""Return the canonical string representation of the search engine.""" | |||||
return "{0}()".format(self.__class__.__name__) | |||||
def __str__(self): | |||||
"""Return a nice string representation of the search engine.""" | |||||
return "<{0}>".format(self.__class__.__name__) | |||||
def search(self, query): | def search(self, query): | ||||
"""Use this engine to search for 'query'. | """Use this engine to search for 'query'. | ||||