grouping placetypes for a TGN place

30 views
Skip to first unread message

Karl Grossner

unread,
Mar 15, 2018, 2:51:56 PM3/15/18
to Getty Vocabularies as Linked Open Data
Hello again,

I'm trying to match a list of place names (~10k) I have with TGN records - an automated reconciliation. For each place name I also have a type and containing country. If I send the following query via the web SPARQL interface I get a single record that I would expect. A related mystery is that when I send the identical query to http://vocab.getty.edu/sparql in Python using SPARQLWrapper, I don't get the single record I get via the web form - rather I get a set 3 of bindings, identical except for the typePref; one record (binding) each for 'inhabited places', 'deserted settlements', and 'ruined settlements'. The place in question has four assigned placetypes according to the TGN search interface: inhabited places (preferred), deserted settlement, etc. as seen here: http://www.getty.edu/vow/TGNFullDisplay?find=abydos&place=&nation=&english=Y&subjectid=6000030


SELECT distinct ?tgnid ?pLab ?typePref ?parents ?note ?lat ?long
{
  ?p skos:inScheme tgn:;
     luc:term "Abydos"; 
     gvp:prefLabelGVP [xl:literalForm ?pLab].
  ?t1 skos:inScheme aat:;
      luc:term "inhabited places";
      gvp:prefLabelGVP [xl:literalForm ?typePref].
  ?p  dc:identifier ?tgnid .
  ?p  gvp:placeTypePreferred ?ptp .
  ?p  gvp:placeType|(gvp:placeType/gvp:broaderGenericExtended) ?t1 .
  ?p  gvp:parentString ?parents .
  ?p  skos:scopeNote [rdf:value ?note] .
  ?p  foaf:focus [wgs:lat ?lat] .
  ?p  foaf:focus [wgs:long ?long] .
  FILTER regex(?parents, "Türkiye", "i")
}

Instead of ?prefType I'd like to group the placetypes (AAT id, label) for each TGN id, and I've tried group_concat(), using the endpoint via the web and in a Python script using the SPARQLWrapper library.

Can anyone lend a hand?

thanks

Vladimir Alexiev

unread,
Mar 16, 2018, 5:58:38 AM3/16/18
to Getty Vocabularies as Linked Open Data
Here's an improved version:

select * {
 
{select ?p (group_concat(?t; separator="; ") as ?types) {
   
?p skos:inScheme tgn: ;
       gvp
:broaderExtended [rdfs:label "Turkey"@en];
       luc
:term "Abydos".
    filter exists
{?p gvp:placeType|(gvp:placeType/gvp:broaderGenericExtended)
       
[rdfs:label "inhabited place"@en]}
   
?p gvp:placeType [gvp:prefLabelGVP [xl:literalForm ?t]] .
 
} group by ?p}
 
?p gvp:prefLabelGVP [xl:literalForm ?pLab];
     dc
:identifier ?tgnid;
     gvp
:parentString ?parents.
  optional
{?p skos:scopeNote [rdf:value ?note]}
  optional
{?p foaf:focus [wgs:lat ?lat; wgs:long ?long]}
}


ptypespLabtgnidparentsnotelatlong
tgn:6000030inhabited places; deserted settlements; archaeological sites; regional capitalsÇanakkale@tr6000030Çanakkale, Türkiye, Asia, WorldLocated northeast of Çanakkale city; Thracians occupied ancient city after Trojan War until settlement by Milesians with permission of Gyges king of Lydia ca. 700 BCE; one end of bridge which Xerxes' army crossed when invading Greece 480 BCE; later became toll station.@en40.15552326.412707

Notes:
  • Don't use luc:term "inhabited places" for the type because you know one of its labels exactly: "inhabited places"@en (singular or plural, it has both).
  • Don't EVER use regex, that's awfully slow. Instead, gvp:broaderExtended [rdfs:label "Turkey"@en] gives you exactly what you need.
  • Do use "optional" for attributes that may be missing.
  • And the reason I use a subquery is to limit the scope of "group by" to only the root variable ?p. If I used it on top level, I'd have to group by a lot more variables.
Cheers!

Karl Grossner

unread,
Mar 16, 2018, 1:27:18 PM3/16/18
to Getty Vocabularies as Linked Open Data
Thanks very much, Vladimir - that does give a good result via the web interface. Also, very helpful tips re: querying TGN

Unfortunately, it either takes several seconds or hangs when I use the Python SPARQLWrapper. So while this pulls the data I need for this record, there are larger issues related to scaling for the overall task. I will follow up separately.

best, Karl
Reply all
Reply to author
Forward
0 new messages