Wikidata:Property proposal/ID pattern

From Wikidata
Jump to navigation Jump to search

Id pattern[edit]

Originally proposed at Wikidata:Property proposal/Generic

   Withdrawn
DescriptionA replacement pattern, to form an external id. to be used with applies if regular expression matches (P8460)
Data typeString
Domainproperty
Allowed valuesvalid replacement pattern with $1 for the first match. $2 for the second and so forth…
Example 1X username (P2002) → [id build pattern] → $1
applies if regular expression matches (P8460)/^https?:\/\/(?:mobile\.)?twitter\.com\/(?:intent\/user\?screen_name\=)?(?!hashtag|home|explore|notifications|messages|i)([0-9A-Za-z_]{1,15})/
Example 2subreddit (P3984) → [id build pattern] → $1
applies if regular expression matches (P8460)/^https?:\/\/www\.reddit\.com\/r\/([^\/?#]+)\/
Example 3MusicBrainz artist ID (P434) → [id build pattern] → $1
applies if regular expression matches (P8460)/^https?:\/\/musicbrainz\.org\/artist\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
Example 4MusicBrainz artist ID (P434) → [id build pattern] → $1
applies if regular expression matches (P8460)/^https?:\/\/www\.bbc\.co\.uk\/music\/artists\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/
Example 5Fandom article ID (P6262) → [id build pattern] → $1:$2
applies if regular expression matches (P8460)/https?:\/\/([a-z0-9\.-]+).fandom\.com\/wiki\/([^\s#\?]+)/
Example 6Fandom article ID (P6262) → [id build pattern] → $2.$1:$3
applies if regular expression matches (P8460)/https?:\/\/([a-z0-9\.-]+).fandom\.com\/([\w]+)\/wiki\/([^\s#\?]+)/
Sourcelist

Motivation[edit]

I am currently working on a browser extension, that – among others – displays wikidata entities for websites the user visits. In order to do that, it must be able to know which websites are associated with which external identifier on wikidata. For instance:


The url https://twitter.com/timberners_lee contains a twitter handle timberners_lee which in Wikidata is associated with Tim Berners-Lee (Q80).

Currently, the extension uses a static list of regular expressions that only a git contributor is able to expand. A wikidata property would make it much more easy to contribute entries to this list. Plus, other extensions could certainly use it too.

It is crucial that the expression only returns a single capture group, that only contains the id. Other groups must be non-capturing. --Shisma (talk) 16:57, 17 November 2020 (UTC)[reply]

Discussion[edit]

@BrokenSegue, Jura1: are there any advantages or disadvantages that one proposal might have over the other? to me it appears like this. --Loominade (talk) 10:22, 23 November 2020 (UTC)[reply]

Proposal comparison
Match pattern ID pattern
Pro: more intuitive Pro: re-uses existing property
Pro: has a default value
@Loominade: that is also my understanding. The match pattern one also allows for a "default" case of "\1" but I'm not sure that matters very much. I really don't care which we go with. BrokenSegue (talk) 17:44, 23 November 2020 (UTC)[reply]
actually I don't like re-using applies if regular expression matches (P8460) for this. the other proposal has been marked as ready yesterday. Perhaps I should withdraw --Shisma (talk) 18:15, 24 November 2020 (UTC)[reply]