Changeset 655

Show
Ignore:
Timestamp:
02/28/07 17:43:11 (2 years ago)
Author:
sgillies
Message:

Allow creation of placeful associations without names (#252)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PleiadesEntity/trunk/Extensions/loader.py

    r648 r655  
    395395    
    396396    for lid in lids: 
    397         for i, nid in enumerate(nids): 
    398             # Get association certainty from XML 
    399             certainty = association_certainties[i] 
    400              
     397        # Handle the unnamed case 
     398        if len(nids) == 0: 
    401399            aid = p.invokeFactory('PlacefulAssociation', 
    402                 id="%s-%s" % (nid,lid)
     400                id="unnamed-%s" % lid
    403401                placeType=placeType, 
    404                 certainty=certainty
     402                certainty='certain'
    405403                ) 
    406404            a = getattr(p, aid) 
    407405            a.addReference(getattr(locations, lid), 'hasLocation') 
    408             a.addReference(getattr(names, nid), 'hasName') 
    409406         
    410407            # Secondary references for the place 
    411408            parse_secondary_references(root, a, ptool) 
    412409            a.reindexObject() 
     410         
     411        else: 
     412            for i, nid in enumerate(nids): 
     413                # Get association certainty from XML 
     414                certainty = association_certainties[i] 
     415             
     416                aid = p.invokeFactory('PlacefulAssociation', 
     417                    id="%s-%s" % (nid,lid), 
     418                    placeType=placeType, 
     419                    certainty=certainty, 
     420                    ) 
     421                a = getattr(p, aid) 
     422                a.addReference(getattr(locations, lid), 'hasLocation') 
     423                a.addReference(getattr(names, nid), 'hasName') 
     424         
     425                # Secondary references for the place 
     426                parse_secondary_references(root, a, ptool) 
     427                a.reindexObject() 
    413428 
    414429    return {'place_id': pid, 'location_ids': lids, 'name_ids': nids} 
  • PleiadesEntity/trunk/tests/LoadEntity.txt

    r651 r655  
    3535    >>> _ = folder.invokeFactory('PlaceContainer', id='places') 
    3636 
    37 Utility tests 
    38 ------------- 
    39  
    40     >>> format_listofstrings([]) 
    41     u'' 
    42     >>> format_listofstrings(['x']) 
    43     u'x' 
    44     >>> format_listofstrings(['x', 'y']) 
    45     u'x and y' 
    46     >>> format_listofstrings(['x', 'y', 'z']) 
    47     u'x, y and z' 
    48      
    49     >>> purifyText(u'aaa') == u'aaa' 
    50     True 
    51     >>> purifyText(u'abab') == u'abab' 
    52     True 
    53     >>> purifyText(u'Magie\U000000A01950,\U000000A0989') == u'Magie 1950, 989' 
    54     True 
    55     
    5637Load one entity 
    5738--------------- 
     
    5940    >>> r = load_place(folder, "%s/batlas-65-2-24-grc.xml" % TEST_DATA) 
    6041    >>> pid = r['place_id'] 
    61     >>> pid > folder.places._v_nextid 
     42    >>> int(pid) <= BA_ID_MAX 
    6243    True 
    6344    >>> r['name_ids'] 
     
    264245    [{'description': 'An ancient settlement, attested during the Classical, Roman and Late Antique periods (modern location: Geyre). It was known in antiquity by the names: Aphrodisias and Ninoe.', 'spatialCoordinates': '37.71446 28.72886 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638753', 'title': 'Aphrodisias/Ninoe/Aphrodisieus', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638753'}] 
    265246 
     247Load one nameless entity 
     248------------------------ 
     249 
     250    >>> r = load_place(folder, "%s/batlas-65-2-101.xml" % TEST_DATA) 
     251    >>> pid = r['place_id'] 
     252    >>> int(pid) <= BA_ID_MAX 
     253    True 
     254    >>> r['name_ids'] 
     255    [] 
     256 
     257    Test associations 
     258 
     259    >>> p = getattr(folder.places, pid) 
     260    >>> contents = p.listFolderContents() 
     261    >>> len(contents) 
     262    1 
     263     
     264    >>> a = contents[0] 
     265    >>> a.getRefs('hasName') 
     266    [] 
     267    >>> a.getPlaceType() 
     268    'fort' 
     269    >>> a.getCertainty() 
     270    'certain' 
     271 
     272    >>> g = IGeoItemSimple(p) 
     273    >>> g.isGeoreferenced() 
     274    True 
     275    >>> g.getInfo() 
     276    {'description': 'An ancient fort, attested during the Roman period (modern location: Emeriye). Its ancient name is not known.', 'spatialCoordinates': '37.1751 31.7324 0.0', 'url': 'http://nohost/plone/Members/test_user_1_/places/638830', 'title': '638830', 'srs': 'EPSG:4326', 'geometryType': 'point', 'id': '638830'} 
     277