Exemplo n.º 1
0
    def save(cls,
             uida,
             uidb,
             judgement,
             decided=False,
             generated=False,
             score=None):
        left_uid, right_uid = cls.sort_uids(uida, uidb)
        obj = cls.get(left_uid, right_uid)
        if obj is None:
            obj = cls()
            obj.project = project.name
            obj.left_uid = left_uid
            obj.right_uid = right_uid
        obj.judgement = judgement
        if judgement is not None:
            decided = True
        obj.generated = generated or obj.generated
        obj.decided = decided or obj.decided
        if score is not None:
            obj.score = float(score)
        session.add(obj)

        # Set entities to enabled.
        if obj.decided:
            entities = chain(Entity.find_by_result(left_uid, right_uid),
                             Entity.find_by_result(right_uid, left_uid))
            for entity in entities:
                if obj.judgement is False:
                    entity.active = False
                else:
                    entity.active = True
        return obj
Exemplo n.º 2
0
    def save(cls, data, origin, query_uid=None, match_uid=None):
        uid = data.pop('uid', None)
        if uid is None:
            raise ValueError("No UID on entity: %r" % data)
        obj = cls.get(uid, query_uid=query_uid, match_uid=match_uid)
        if obj is None:
            obj = cls()
            obj.project = project.name
            obj.uid = uid
            obj.canonical_uid = uid
            obj.query_uid = query_uid
            obj.match_uid = match_uid

        obj.origin = origin
        obj.schema = data.pop('schema', None)
        if obj.schema not in TYPES:
            raise ValueError("Invalid entity type: %r", data)

        obj.tasked = parse_boolean(data.pop('tasked', None), default=False)
        obj.active = parse_boolean(data.pop('active', None), default=True)
        obj.data = obj.parse_data(data)
        session.add(obj)

        Address.delete_by_entity(uid)
        Address.save(uid, obj.data.get('address'), origin)
        return obj
Exemplo n.º 3
0
 def save(cls, entity_uid, address, origin):
     if entity_uid is None:
         raise ValueError("No UID on address: %r" % address)
     address = stringify(address)
     if address is None:
         return
     obj = cls.get(entity_uid, address, origin=origin)
     if obj is None:
         obj = cls()
         obj.project = project.name
         obj.origin = origin
         obj.entity_uid = entity_uid
         obj.address = address
     obj.slug = slugify(obj.clean, sep=' ')
     session.add(obj)
     return obj
Exemplo n.º 4
0
 def save(cls, data, origin):
     source_uid = data.pop('source_uid', None)
     target_uid = data.pop('target_uid', None)
     if source_uid is None or target_uid is None:
         raise ValueError("No UID on link: %r" % data)
     obj = cls.get(source_uid, target_uid, origin=origin)
     if obj is None:
         obj = cls()
         obj.project = project.name
         obj.origin = origin
         obj.source_uid = source_uid
         obj.source_canonical_uid = source_uid
         obj.target_uid = target_uid
         obj.target_canonical_uid = target_uid
     obj.schema = data.pop('schema', None)
     obj.data = obj.parse_data(data)
     session.add(obj)
     return obj
Exemplo n.º 5
0
    def save(cls, entity_uid, url, title, origin, uid=None, publisher=None):
        url = parse_url(url)
        if url is None:
            raise ValueError("No URL on document!")
        if entity_uid is None:
            raise ValueError("No UID on document: %r" % url)
        if uid is None:
            uid = unicode(sha1(url.encode('utf-8')).hexdigest())

        obj = cls.get(entity_uid, uid, origin)
        if obj is None:
            obj = cls()
            obj.project = project.name
            obj.origin = origin
            obj.entity_uid = entity_uid
            obj.uid = uid

        obj.url = url
        obj.title = stringify(title) or url
        obj.publisher = publisher
        session.add(obj)
        return obj