HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
ftests.ftest_getSentencesString Namespace Reference

Functions

def getWordsCount (string, method=0)
 Get words count in string with different methods. More...
 
def getSentencesString (tagValue, maxSentences=1, maxWordsTotal=0)
 Get sentences from content. More...
 

Variables

list ss
 

Function Documentation

◆ getSentencesString()

def ftests.ftest_getSentencesString.getSentencesString (   tagValue,
  maxSentences = 1,
  maxWordsTotal = 0 
)

Get sentences from content.

Parameters
tagValue
maxSentences
maxWordsTotal
Returns
content contains sentences that was cut with limits

Definition at line 31 of file ftest_getSentencesString.py.

31 def getSentencesString(tagValue, maxSentences=1, maxWordsTotal=0):
32  ret = tagValue
33 
34  sDelimChars = ['.', '!', '?']
35  entrances = 0
36  pos = 0
37  while True:
38  for sDelimChar in sDelimChars:
39  pos = tagValue.find(sDelimChar, pos + 1)
40  if pos != -1:
41  entrances += 1
42  break
43  if pos == -1 or (pos != -1 and entrances >= maxSentences) or ((pos + 1) >= len(tagValue)):
44  break
45 
46  if pos != -1 and pos < len(tagValue):
47  ret = tagValue[:pos + 1]
48 
49  if maxWordsTotal > 0:
50  wc = getWordsCount(ret)
51  if wc > maxWordsTotal:
52  pos = 0
53  posRes = 0
54  wc = 0
55  while True:
56  pos = ret.find(' ', pos + 1)
57  if (pos != -1) and (wc < maxWordsTotal) and ((pos + 1) < len(ret)):
58  wc += 1
59  posRes = pos
60  else:
61  break
62  if posRes != -1:
63  ret = ret[:posRes]
64 
65  return ret
66 
def getSentencesString(tagValue, maxSentences=1, maxWordsTotal=0)
Get sentences from content.
def getWordsCount(string, method=0)
Get words count in string with different methods.
Here is the call graph for this function:

◆ getWordsCount()

def ftests.ftest_getSentencesString.getWordsCount (   string,
  method = 0 
)

Get words count in string with different methods.

Parameters
stringto calculate words count
Returns
the words number

Definition at line 10 of file ftest_getSentencesString.py.

10 def getWordsCount(string, method=0):
11  ret = 0
12 
13  if method == 0:
14  r = re.compile(r'[{}]'.format(punctuation))
15  new_strs = r.sub(' ', string)
16  ret = len(new_strs.split())
17  elif method == 1:
18  ret = len(re.findall(r'\w+', string))
19  else:
20  ret = len(string.split())
21 
22  return ret
23 
24 
def getWordsCount(string, method=0)
Get words count in string with different methods.
Here is the caller graph for this function:

Variable Documentation

◆ ss

list ftests.ftest_getSentencesString.ss
Initial value:
1 = ["",
2  " ",
3  ".",
4  "..",
5  ". .",
6  " . .",
7  "The test sentence1. The sentence2. The sentence 3..",
8  ".The test sentence1. The sentence2. The sentence 3..",
9  " . The test sentence1. The sentence2. The sentence 3..",
10  "Thetestsentence1Thesentence2Thesentence",
11  ]

Definition at line 67 of file ftest_getSentencesString.py.