def __find_predicate(self, product1, product2): # Placeholder predicates # MUCH_SMALLER_THAN = "/r/MuchSmallerThan" SMALLER_THAN = "/r/SmallerThan" EQUIVALENT_TO = "/r/EquivalentTo" LARGER_THAN = "/r/LargerThan" # MUCH_LARGER_THAN = "/r/MuchLargerThan" CANT_COMPARE = "/r/Can'tCompare" """ Find the appropriate predicate for two WdcProductSize objects """ pred = None if not product1.bucket or not product2.bucket: pred = CANT_COMPARE elif product1.bucket > product2.bucket: pred = LARGER_THAN elif product1.bucket < product2.bucket: pred = SMALLER_THAN else: pred = EQUIVALENT_TO return KgEdge.with_generated_id( subject=product1.name, object=product2.name, predicate=pred, source_ids=(WDC_DATASOURCE_ID, ), )
def map(self, node: KgNode) -> Generator[KgEdge, None, None]: """ Given a node from another data source, generate a sequence of edges mapping that node to ConceptNet concepts. """ for node_label in node.labels: concept_net_id = self.__concept_net_index.get( label=node_label, pos=node.pos ) if concept_net_id is None: continue yield KgEdge.with_generated_id( object=concept_net_id, predicate=mowgli_predicates.SAME_AS, source_ids=node.source_ids, subject=node.id, ) return