Skip to content

Commit

Permalink
Extend option ids to more URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Oct 19, 2015
1 parent 4e555b5 commit a4a71a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions bin/wdq
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 203,13 @@ my $ENTITY_PATTERN = qr{^
(?<id>(q|(Property:)?p)\d )
$}ix;

my $WIKIDATA_ID_PATTERN = qr{^
http://www\.wikidata\.org/
( entity (/statement)? | reference | value |
prop (/(statement|qualifier|reference)/value)?)
/(?<id>. )
$}x;

my $SITELINK_PATTERN = qr{^https?://(
[^.] .(
wikipedia | wiktionary | wikibooks | wikiquote | wikisource |
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a4a71a0

Please sign in to comment.