scholia icon indicating copy to clipboard operation
scholia copied to clipboard

"Illegal group reference" in Identifiers panel in chemical class

Open fnielsen opened this issue 6 months ago • 3 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to http://127.0.0.1:8100/chemical-class/Q61476#identifiers or https://scholia.toolforge.org/chemical-class/Q61476#identifiers
  2. "This query has timed out"
  3. Go further on to WD query
  4. Press blue button
  5. "Illegal group reference"

Expected behavior Something should be returned

Screenshots

Image

Additional context There is no http://127.0.0.1:8100/chemical-class/Q46995757#identifiers content. Is this because of a Scholia problem or the data?

fnielsen avatar Jun 20 '25 20:06 fnielsen

This seems to work:

PREFIX target: <http://www.wikidata.org/entity/Q61476>

SELECT
  ?IDpred ?IDpredLabel
  ?id ?idUrl
  ?IDpredDescription
{
  target: ?IDdir ?id .
  ?IDpred wikibase:directClaim ?IDdir ;
            wdt:P31 wd:Q19833835 .
  OPTIONAL {
    ?IDpred wdt:P1630 ?formatterurl .
    BIND(IRI(REPLACE(?formatterurl, '\\$1', str(?id))) AS ?idUrl).
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
}
ORDER BY ASC(?IDpredLabel)
LIMIT 500

fnielsen avatar Jun 20 '25 20:06 fnielsen

The problems seems to be "OC([*])=O |$;;R;$|" in https://www.wikidata.org/wiki/Q61476. There are several dollar signs in the identifier. This confuses the REPLACE function and one would need to escape the dollar sign.

This seems to work:

PREFIX target: <http://www.wikidata.org/entity/Q61476>

SELECT
  (REPLACE(STR(?identifier), "\\$", "\\\\\\\\\\$") AS ?test)
  (?identifierLabel AS ?identifier_) ?identifier_Url
  ?url_pattern
  ?property_item ?property_itemLabel ?property_itemDescription
WHERE {
  target: ?IDdir ?identifier .
  ?property_item wikibase:directClaim ?IDdir ;
                 wdt:P31 wd:Q19833835 .
  OPTIONAL {
    ?property_item wdt:P1630 ?url_pattern . 
  }
  BIND(CONCAT(?identifier, "&nbsp;↗") AS ?identifierLabel)
  BIND(REPLACE(STR(?identifier), "\\$", "--ESCAPED DOLLARS SIGN--") AS ?escaped_identifier)
  BIND((REPLACE(?url_pattern, "\\$1", ?escaped_identifier)) AS ?identifier_Url_)
  BIND(IRI(REPLACE(?identifier_Url_, "--ESCAPED DOLLARS SIGN--", "\\$")) AS ?identifier_Url)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }

But it looks crazy.

fnielsen avatar Jun 25 '25 21:06 fnielsen

5. "Illegal group reference"

@fnielsen, sorry, I seem to have missed this bug report. On my radar now.

egonw avatar Aug 23 '25 13:08 egonw