def test_message_set_facts_always_list2(self): message = Message(self.fact1, 0.1, 0.2, 0.3) message.facts = [self.fact2] self.assertIsInstance(message.facts, list) self.assertListEqual(message.facts, [self.fact2]) self.assertEqual(message.main_fact, self.fact2)
def setUp(self): self.fact1 = Fact( "action", "action1", "parameters", "id", ) self.fact2 = Fact( "action", "action2", "parameters", "id", ) self.message1 = Message(self.fact1) self.message2 = Message(self.fact2) self.expr = FactField("name") self.matcher = Matcher(self.expr, "=", "action1") self.rules = [([self.matcher], [0])] self.slot = Slot(FactFieldSource("name")) self.literal = LiteralSlot("literal") self.components = [self.slot, self.literal] self.template = Template(self.components, self.rules)
def test_message_creation_list_of_facts(self): message = Message([self.fact1, self.fact2], 0.1, 0.2, 0.3) self.assertIsInstance(message.facts, list) self.assertEqual(len(message.facts), 2) self.assertListEqual(message.facts, [self.fact1, self.fact2]) self.assertEqual(message.main_fact, self.fact1)
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "crosslingual comparison": return [] return [ Message(Fact("reason", "crosslingual_comparison", None, event.id)) ]
def setUp(self): self.fact = Fact( "action", "action1", "parameters", "id", ) self.message = Message(self.fact, 0.1, 0.2, 0.3) self.source = FactFieldSource("name")
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "same language collections": return [] return [ Message(Fact("reason", "same_language_collections", None, event.id)) ]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "FindBestSplitFromTimeseries": return [] return [ Message(Fact("task", "FindBestSplitFromTimeseries", None, event.id)) ]
def parse_reason(self, event: Event) -> List[Message]: reason = event.reason if not reason or reason.name != "path strategy": return [] return [ Message( Fact("reason", "path_strategy_{}".format(reason.strategy), None, event.id)) ]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "SplitByFacet": return [] return [ Message( Fact( "task", "SplitByFacet", "[SplitByFacet:FACET:{}]".format( task.parameters.get("facet")), event.id)) ]
def setUp(self): self.fact1 = Fact( "action", "action1", "parameters", "id", ) self.message1 = Message(self.fact1, 0.1, 0.2, 0.3) self.fact2 = Fact( "action", "action2", "parameters", "id", ) self.message2 = Message(self.fact2, 0.1, 0.2, 0.3) self.document_plan_node = DocumentPlanNode( [self.message1, self.message2], Relation.ELABORATION) self.document = Document("en", self.document_plan_node)
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "GenerateTimeSeries": return [] if "facet_name" in task.parameters: split_by = "[TimeSeries:FACET:{}]".format( task.parameters.get("facet_name")) else: split_by = "[TimeSeries:NO_FACET]" return [ Message(Fact("task", "GenerateTimeSeries", split_by, event.id)) ]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "TopicModelDocsetComparison": return [] return [ Message( Fact( "task", "TopicModelDocsetComparison", None, event.id, )) ]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "ExtractWords": return [] return [ Message( Fact( "task", "ExtractWords", "[ExtractWords:UNIT:{}]".format( task.parameters.get("units", "stems")), event.id, )) ]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "QueryTopicModel": return [] return [ Message( Fact( "task", "QueryTopicModel", "[QueryTopicModel:NAME:{}] [QueryTopicModel:TYPE:{}]". format(task.parameters.get("model_name"), task.parameters.get("model_type")), event.id, )) ]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "ExtractNames": return [] return [ Message( Fact( "task", "ExtractNames", "[ExtractNames:{}:{}]".format( event.task.parameters.get("sort_by"), event.task.parameters.get("max_number")), event.id, )) ]
def test_message_creation_single_fact(self): message = Message(self.fact1, 0.1, 0.2, 0.3) self.assertIsInstance(message.facts, list) self.assertNotIsInstance(message.facts, Fact) self.assertEqual(len(message.facts), 1) self.assertEqual(message.facts[0], self.fact1) self.assertEqual(message.main_fact, self.fact1) self.assertEqual(message.importance_coefficient, 0.1) self.assertEqual(message.score, 0.2) self.assertEqual(message.polarity, 0.3) self.assertIsNone(message.template) self.assertEqual( str(message), "<Message: fact(type='action', name='action1', parameters='parameters', id='id')>", )
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "Comparison": return [] if task.parameters.get("facet"): params = "[Comparison:Task:Facet:{}]".format( task.parameters["facet"]) else: params = "[Comparison:Task:Unknown]" return [Message(Fact( "task", "Comparison", params, event.id, ))]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "TopicModelDocumentLinking": return [] return [ Message( Fact( "task", "TopicModelDocumentLinking", "[TopicModelDocumentLinking:NAME:{}] [TopicModelDocumentLinking:TYPE:{}]".format( task.parameters.get("model_name"), task.parameters.get("model_type") ), event.id, ) ) ]
def setUp(self): self.fact = Fact( "1", "kissa", "params", "id", ) self.message = Message(self.fact) self.expr = FactField("type") self.matcher = Matcher(self.expr, "=", "1") self.rules = [([self.matcher], [0])] self.slot = Slot(FactFieldSource("name")) self.literal = LiteralSlot("sana") self.components = [self.slot, self.literal] self.template = Template(self.components, self.rules) self.template.fill(self.message, [self.message]) self.realizer = FinnishUralicNLPMorphologicalRealizer()
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "ExpandQuery": return [] return [Message(Fact("task", "ExpandQuery", None, event.id))]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "Summarization": return [] return [Message(Fact("task", "Summarization", None, event.id))]
def parse_task(self, event: Event) -> List[Message]: task = event.task if not task or task.name != "TrackNameSentiment": return [] return [Message(Fact("task", "TrackNameSentiment", None, event.id))]
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "impossible to split": return [] return [Message(Fact("reason", "impossible_to_split", None, event.id))]
def run(self, registry: Registry, random: Generator, language: str, data: List[Dict[str, str]]) -> Tuple[List[Message]]: """ Run this pipeline component. """ if not data: raise NoMessagesForSelectionException("No data at all!") task_parsers: List[Callable[[Event], List[Message]]] = registry.get( "task-parsers") reason_parsers: List[Callable[[Event], List[Message]]] = registry.get( "reason-parsers") events: List[Event] = [ Event.from_dict(event) for event in json.loads(data) ] events.sort( key=lambda event: event.id) # Smaller ID indicates earlier event messages: List[Message] = [] for event in events: task_generation_succeeded = False for task_parser in task_parsers: try: new_messages = task_parser(event) for message in new_messages: log.debug("Parsed message {}".format(message)) if new_messages: task_generation_succeeded = True messages.extend(new_messages) except Exception as ex: log.error("Task parser crashed: {}".format(ex), exc_info=True) if not task_generation_succeeded: messages.append( Message( Fact("task", "UNKNOWN_TASK:{}".format(event.task.name), event.task.parameters, event.id))) log.error("Failed to parse a Message from {}".format( event.task)) reason_generation_succeeded = False for reason_parser in reason_parsers: try: new_messages = reason_parser(event) for message in new_messages: log.debug("Parsed message {}".format(message)) if new_messages: reason_generation_succeeded = True messages.extend(new_messages) except Exception as ex: log.error("Reason parser crashed: {}".format(ex), exc_info=True) if not reason_generation_succeeded: messages.append( Message( Fact("reason", "UNKNOWN_REASON:{}".format(event.reason.name), event.reason.parameters, event.id))) log.error("Failed to parse a Message from {}".format( event.reason)) log.debug("Generated {} messages".format(len(messages))) if not messages: raise NoMessagesForSelectionException() return (messages, )
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "not enough data": return [] return [Message(Fact("reason", "not_enough_data", None, event.id))]
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "initialization": return [] return [Message(Fact("reason", "initialization", None, event.id))]
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "interesting results": return [] return [Message(Fact("reason", "interesting_results", None, event.id))]
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "brute_force": return [] return [Message(Fact("reason", "BruteForce", None, event.id))]
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "nothing-to-compare": return [] return [Message(Fact("reason", "nothing_to_compare", None, event.id))]
def parse_reason(self, event: Event) -> List[Message]: task = event.reason if not task or task.name != "path stop": return [] return [Message(Fact("reason", "path_stop", None, event.id))]