There are multiple entity IDs for URI .... Please resolve. The first one is taken.

Problem

If you import data directly with sparql or get some from other adapters like gnd or geonames, the system sometimes create multiple views (connected via owl:sameAs properties), so that for one entity uri exists multiply entity ids.

Solution

The records referring to unnecessary entity id must be deleted from both the triple store and the database.

Steps

First go to your DBMS and delete the duplicates from the wisski_salz_id2uri table via a sql query:

DELETE FROM wisski_salz_id2uri t1 INNER JOIN wisski_salz_id2uri t2 WHERE t1.eid > t2.eid AND t1.uri = t2.uri AND t1.adapter_id = t2.adapter_id

After that go to your triple store and use this sparl query (where "your_namespace" is your ontology-namespace like "http://www.wikidata.org/wiki"

PREFIX owl: <http://www.w3.org/2002/07/owl#>
DELETE {?s owl:sameAs ?max}
WHERE {
    ?s owl:sameAs ?max
    {
        SELECT DISTINCT ?uri ?drp1 ?drp2 ?max WHERE { GRAPH <your_namespace/originatesFrom>
        { ?drp1 <http://www.w3.org/2002/07/owl#sameAs> ?uri .
        ?drp1 <your_namespace/originatesFrom> 'drupal_id' .
        ?drp2 <http://www.w3.org/2002/07/owl#sameAs> ?uri .
        ?drp2 <your_namespace/originatesFrom> 'drupal_id' .
        FILTER (?drp1 != ?drp2) .
        FILTER(strStarts(STR(?drp1), "your_namespace/wisski/navigate/")) .
        BIND( IF(STRLEN(STR(?drp1)) = STRLEN(STR(?drp2)), IF(STR(?drp1) < STR(?drp2), ?drp2, ?drp1), IF(STRLEN(STR(?drp1)) > STRLEN(STR(?drp2)), ?drp1, ?drp2)) AS ?max) .
        FILTER(strStarts(STR(?drp2), "your_namespace/wisski/navigate/")) } . }
        ORDER BY DESC(?uri)
    }
}

There should be no more duplicates, check in your DBMS with

select t1.* FROM wisski_salz_id2uri t1 INNER JOIN wisski_salz_id2uri t2 WHERE t1.eid > t2.eid AND t1.uri = t2.uri AND t1.adapter_id = t2.adapter_id

and in your triple store with

PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?s ?o ?eid
WHERE {
    ?s owl:sameAs ?o
    FILTER (strstarts(str(?s), "your_namespace/content/")
        && strstarts(str(?o), "your_namespace/wisski/navigate/"))
    {
        SELECT ?s
        WHERE {
            ?s owl:sameAs ?o.
            FILTER (strstarts(str(?s), "your_namespace/content/")
                && strstarts(str(?o), "your_namespace/wisski/navigate/")
            )
        }
        GROUP BY ?s
        HAVING (count(?s) >1 )
    }
}