Project:RedirectionScript: Difference between revisions
From MaRDI portal
Created page with "Test" |
No edit summary |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== SPARQL queries == | |||
=== Count number of items that redirect to another item === | |||
<syntaxhighlight lang="sparql"> | |||
SELECT (COUNT (DISTINCT ?o) AS ?count) | |||
WHERE | |||
{ | |||
?o owl:sameAs ?sa . | |||
} | |||
</syntaxhighlight> | |||
=== Get mapping of original items to the ones they were redirected to === | |||
This query gets all original items (?o) that get redirected to another item (?sa). We need these results because for each original item, the script looks for items that link to it. Then, it replaces the link on these original items with a link to the ?sa item.<syntaxhighlight lang="sparql"> | |||
SELECT DISTINCT ?o ?sa | |||
WHERE | |||
{ | |||
?o owl:sameAs ?sa . | |||
} | |||
</syntaxhighlight> | |||
=== Get all items that redirect to somewhere else and are still referenced in another item === | |||
Exclude those without a label to exclude other reference pages<syntaxhighlight lang="sparql"> | |||
SELECT DISTINCT ?o | |||
WHERE | |||
{ | |||
?o owl:sameAs ?sa . | |||
?new ?p ?o . | |||
?o rdfs:label ?label . | |||
} | |||
</syntaxhighlight> | |||
== Script == | |||
https://github.com/MaRDI4NFDI/docker-importer/blob/main/bot_scripts/reroute.py | |||
The script takes as input a csv file with the output of the second sparql query that maps old ids to new ids. | |||
== Potential Problems == | |||
If for a specific item, the problem is not fixed after executing this script, it might be that the item was not correctly indexed. This can be fixed by using [[Project:RerunUpdate]] and then rerunning the script. | |||
Latest revision as of 10:54, 21 March 2025
SPARQL queries
Count number of items that redirect to another item
SELECT (COUNT (DISTINCT ?o) AS ?count)
WHERE
{
?o owl:sameAs ?sa .
}
Get mapping of original items to the ones they were redirected to
This query gets all original items (?o) that get redirected to another item (?sa). We need these results because for each original item, the script looks for items that link to it. Then, it replaces the link on these original items with a link to the ?sa item.
SELECT DISTINCT ?o ?sa
WHERE
{
?o owl:sameAs ?sa .
}
Get all items that redirect to somewhere else and are still referenced in another item
Exclude those without a label to exclude other reference pages
SELECT DISTINCT ?o
WHERE
{
?o owl:sameAs ?sa .
?new ?p ?o .
?o rdfs:label ?label .
}
Script
https://github.com/MaRDI4NFDI/docker-importer/blob/main/bot_scripts/reroute.py
The script takes as input a csv file with the output of the second sparql query that maps old ids to new ids.
Potential Problems
If for a specific item, the problem is not fixed after executing this script, it might be that the item was not correctly indexed. This can be fixed by using Project:RerunUpdate and then rerunning the script.