45 rql += ', X is IN (%s)' % ','.join(etypes) |
46 rql += ', X is IN (%s)' % ','.join(etypes) |
46 if source_eid is not None: |
47 if source_eid is not None: |
47 rql += ', X cw_source S, S eid %(s)s' |
48 rql += ', X cw_source S, S eid %(s)s' |
48 args['s'] = source_eid |
49 args['s'] = source_eid |
49 return dict(cnx.execute(rql, args)) |
50 return dict(cnx.execute(rql, args)) |
|
51 |
|
52 |
|
53 def use_extid_as_cwuri(extid2eid): |
|
54 """Return a generator of :class:`ExtEntity` objects that will set `cwuri` |
|
55 using entity's extid if the entity does not exist yet and has no `cwuri` |
|
56 defined. |
|
57 |
|
58 `extid2eid` is an extid to eid dictionary coming from an |
|
59 :class:`ExtEntitiesImporter` instance. |
|
60 |
|
61 Example usage: |
|
62 |
|
63 .. code-block:: python |
|
64 |
|
65 importer = SKOSExtEntitiesImporter(cnx, store, import_log) |
|
66 set_cwuri = use_extid_as_cwuri(importer.extid2eid) |
|
67 importer.import_entities(set_cwuri(extentities)) |
|
68 """ |
|
69 def use_extid_as_cwuri_filter(extentities): |
|
70 for extentity in extentities: |
|
71 if extentity.extid not in extid2eid: |
|
72 extentity.values.setdefault('cwuri', set([unicode(extentity.extid)])) |
|
73 yield extentity |
|
74 return use_extid_as_cwuri_filter |
50 |
75 |
51 |
76 |
52 class RelationMapping(object): |
77 class RelationMapping(object): |
53 """Read-only mapping from relation type to set of related (subject, object) eids. |
78 """Read-only mapping from relation type to set of related (subject, object) eids. |
54 |
79 |