def __init__(self):
     self.appender = ReaderWriter()
     self.mapper_reader = self._mapper_reader()
     self.mapper_appender = ReaderWriter()
     self.reader = self._reader()
     self.extractor = m.EntityExtractor(
         #                 in/output: ab_id    entity-mapper: id
         ref_field_map=FieldsMap.parse('id=ab_id'),
         #                 in/output: a, b     entity-mapper: a, other
         fields_map=FieldsMap.parse('a,other=b'),
         keep_fields=True)
 def __init__(self):
     self.appender = ReaderWriter()
     self.mapper_reader = self._mapper_reader()
     self.mapper_appender = ReaderWriter()
     self.reader = self._reader()
     self.extractor = m.EntityExtractor(
         #                 in/output: ab_id    entity-mapper: id
         ref_field_map=FieldsMap.parse('id=ab_id'),
         #                 in/output: a, b     entity-mapper: a, other
         fields_map=FieldsMap.parse('a,other=b'),
         keep_fields=True)
Beispiel #3
0
def main():
    reader = csv.reader(sys.stdin)
    writer = csv.writer(sys.stdout)
    entity_fields, ref_field, entity_file = sys.argv[1:]

    extractor = EntityExtractor(FieldsMap.parse(ref_field),
                                FieldsMap.parse(entity_fields),
                                keep_fields=True)

    has_entity_file = os.path.exists(entity_file)

    with open(entity_file, 'a+') as f:
        if has_entity_file:
            extractor.use_existing_mapper(csv.reader(f), csv.writer(f))
        else:
            extractor.use_new_mapper(csv.writer(f))
        extractor.extract(reader, writer)
Beispiel #4
0
def main():
    reader = csv.reader(sys.stdin)
    writer = csv.writer(sys.stdout)
    entity_fields, ref_field, entity_file = sys.argv[1:]

    extractor = EntityExtractor(
        FieldsMap.parse(ref_field),
        FieldsMap.parse(entity_fields),
        keep_fields=True)

    has_entity_file = os.path.exists(entity_file)

    with open(entity_file, 'a+') as f:
        if has_entity_file:
            extractor.use_existing_mapper(csv.reader(f), csv.writer(f))
        else:
            extractor.use_new_mapper(csv.writer(f))
        extractor.extract(reader, writer)