MCPcopy Create free account
hub / github.com/IENT/YUView / VariableDescription

Class VariableDescription

tools/standardTextToCode/parseVariableDescriptions.py:35–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33
34
35class VariableDescription():
36 def __init__(self, name):
37 self.name = name
38 self.description = ""
39 self.shallBe = None
40
41 def __str__(self):
42 if (self.shallBe):
43 return f"{self.name} -- {self.shallBe}"
44 else:
45 return f"{self.name}"
46
47 def finishReading(self):
48 self.cleanDescriptionText()
49 self.lookForShallBe()
50
51 def cleanDescriptionText(self):
52 self.description = self.description.replace(u'\xa0', u' ')
53
54 def lookForShallBe(self):
55 searchStrings = []
56 searchStrings.append(self.name + " shall be ")
57 searchStrings.append("the value of " + self.name + " shall be ")
58 for searchString in searchStrings:
59 posShallBe = self.description.lower().find(searchString)
60 if (posShallBe != -1):
61 posDot = self.description.find(".", posShallBe)
62 if (posDot != -1):
63 self.parseRestriction(
64 self.description[posShallBe + len(searchString): posDot])
65 return
66
67 def parseRestriction(self, restrictionText):
68 conditionList = ["in the range of ", "greater than ",
69 "greater then ", "less than ", "less then ", "equal to "]
70 for idx, condition in enumerate(conditionList):
71 conditionPos = restrictionText.find(condition)
72 conditionStart = conditionPos + len(condition)
73 if (conditionPos != -1):
74 conditionIndex = idx
75 break
76 if (conditionPos == -1):
77 ignoreCases = ["the same for all pictures ",
78 "the same in all ",
79 "the same for all PPSs "]
80 for c in ignoreCases:
81 if (c in restrictionText):
82 return
83 if (restrictionText == "0"):
84 print("Warning: Restriction just says 'shall be 0'.")
85 self.shallBe = VariableRestrictionEqualTo("0")
86 return
87 print("TODO: Add this restriction: " + restrictionText)
88 return
89
90 if (conditionIndex == 0):
91 posMinEnd = restrictionText.find(" to ", conditionStart)
92 posMaxStart = posMinEnd + len(" to ")

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected