diff --git a/Changes b/Changes index b51d8e1..5659684 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for App-wdq {{$NEXT}} - New option no-header to omit header in CSV or export format + - Extend option ids to more types of Wikidata URIs 0.3.3 2015-10-17 21:11:41 CEST - Better abbreviated URIs as qnames diff --git a/bin/wdq b/bin/wdq index 154dd24..8a8d620 100755 --- a/bin/wdq +++ b/bin/wdq @@ -203,6 +203,13 @@ my $ENTITY_PATTERN = qr{^ (?(q|(Property:)?p)\d+) $}ix; +my $WIKIDATA_ID_PATTERN = qr{^ + http://www\.wikidata\.org/ + ( entity (/statement)? | reference | value | + prop (/(statement|qualifier|reference)/value)?) + /(?.+) +$}x; + my $SITELINK_PATTERN = qr{^https?://( [^.]+.( wikipedia | wiktionary | wikibooks | wikiquote | wikisource | @@ -459,10 +466,16 @@ sub parse_response { foreach my $name ( keys %$r ) { my $v = $r->{$name}; next unless $v->isa('RDF::Trine::Node::Resource'); - next - if $v->uri_value !~ -qr{^http://www.wikidata.org/(entity|prop)(/[^/]+)?/([QP]\d+|[a-z0-9]+)$}; - $r->{$name} = RDF::Trine::Node::Literal->new($3); + my $id = do { + if ( $v->uri_value =~ $ENTITY_PATTERN ) { + $+{id}; + } + elsif ( $v->uri_value =~ $WIKIDATA_ID_PATTERN ) { + $+{id}; + } + } + // next; + $r->{$name} = RDF::Trine::Node::Literal->new($id); } $r; }