def strip_around(sentence: Sentence, border_type: str, split: bool) -> tuple[tuple[Sentence]]: """Dzieli zdanie wokół głównego spójnika, jeśli spójnikiem jest `border_type` :param sentence: zdanie do podziału :type sentence: Sentence :param border_type: typ spójnika, wokół którego dzielone będzie zdanie :type border_type: str :param split: Czy tworzyć nowe gałęzie? :type split: bool :return: Struktura krotek :rtype: tuple[tuple[Sentence]] """ if not sentence or len(sentence) == 1: return None middle, subsents = sentence.getComponents() if middle is None or middle.split('_')[0] != border_type: return None left, right = subsents if split: return ((left, ), (right, )) else: return ((left, right), )
def convert_to_signed(s: Sentence): conn, a = s.getComponents() if a is None: return [s.generate('signtrue')] + s.reduceBrackets() else: (_, form) = a if conn.startswith('not_'): return [s.generate('signfalse')] + form.reduceBrackets() else: return [s.generate('signtrue')] + s.reduceBrackets()
def find_rule(sentence: Sentence) -> str: main, other = sentence.getComponents() if main is None: return None if main.startswith('not_'): negated = 'false' main, _ = other.getComponents() else: negated = 'true' if main.startswith('not_'): return 'double not' else: return f"{negated} {main.split('_')[0]}"
def find_rule(sentence: Sentence) -> str: """ Rozpoznaje jaka reguła powinna zostać użyta na formule """ main, other = sentence.getComponents() if main is None: return None elif main.startswith('not_'): negated = 'false' second, _ = other[1].getComponents() else: negated = 'true' second = main if second is None: return None elif second.startswith('not_'): return 'double not' else: return f"{negated} {second.split('_')[0]}"
def reduce_prefix(sentence: Sentence, prefix_type: str) -> Sentence: """Usuwa prefiksy ze zdań :param sentence: zdanie do modyfikacji :type sentence: Sentence :param prefix_type: typ prefiksu do usunięcia :type prefix_type: str :param precedence: Kolejność wykonywania działań :type precedence: dict[str, int] :return: Nowe zdanie :rtype: Sentence """ if not sentence or len(sentence) == 1: return None middle, subsents = sentence.getComponents() if middle is None or not middle.startswith(prefix_type): return None _, right = subsents return right
def test_simple(self): sentence = Sentence(['sentvar_p', 'or_or', 'sentvar_q'], None) result = ('or_or', (['sentvar_p'], ['sentvar_q'])) self.assertEqual(sentence.getComponents(self.precedence), result)