Skip to content

Instantly share code, notes, and snippets.

@takemikami
Last active September 7, 2019 05:22
Show Gist options
  • Save takemikami/a9239bc947a962cda2ff21153e9d2232 to your computer and use it in GitHub Desktop.
Save takemikami/a9239bc947a962cda2ff21153e9d2232 to your computer and use it in GitHub Desktop.
im@sparqlのサンプルクエリ
PREFIX schema: <http://schema.org/>
PREFIX imas: <https://sparql.crssnky.xyz/imasrdf/URIs/imas-schema.ttl#>
SELECT (concat(group_concat(?nm1; separator=''), ' ', group_concat(?nm2; separator=''), ' ', group_concat(?nm3; separator='')) as ?h)
WHERE {
{ SELECT (1 as ?g) (?nm as ?nm1) ("" as ?nm2) ("" as ?nm3)
WHERE { ?s imas:nameKana ?nm. FILTER (strlen(str(?nm)) = 5) }
ORDER BY RAND() LIMIT 1
} UNION { SELECT (1 as ?g) ("" as ?nm1) (?nm as ?nm2) ("" as ?nm3)
WHERE { ?s imas:nameKana ?nm. FILTER (strlen(str(?nm)) = 7) }
ORDER BY RAND() LIMIT 1
} UNION { SELECT (1 as ?g) ("" as ?nm1) ("" as ?nm2) (?nm as ?nm3)
WHERE { ?s imas:nameKana ?nm. FILTER (strlen(str(?nm)) = 5) }
ORDER BY RAND() LIMIT 1
}
} GROUP BY ?g
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX schema: <http://schema.org/>
PREFIX imas: <https://sparql.crssnky.xyz/imasrdf/URIs/imas-schema.ttl#>
SELECT (group_concat(concat(' ', str(?cnt), ' ', if(contains(str(?o), "#"), strafter(str(?o), "#"), strafter(str(?o), str(schema:))), 's'); separator=',') as ?stat)
WHERE {
SELECT ?o (COUNT(?s) AS ?cnt)
WHERE {
?s rdf:type ?o FILTER (?o IN (imas:Idol, imas:Unit, imas:Clothes))
}
GROUP BY ?o
}
PREFIX schema: <http://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX imas: <https://sparql.crssnky.xyz/imasrdf/URIs/imas-schema.ttl#>
SELECT ?uname (sum(?len5) as ?c5) (sum(?len7) as ?c7) (sum(?lenelse) as ?ce)
{
SELECT
?uname
(if(strlen(str(?nm))=5, 1, 0) as ?len5)
(if(strlen(str(?nm))=7, 1, 0) as ?len7)
(if(strlen(str(?nm))=5 || strlen(str(?nm))=7, 0, 1) as ?lenelse)
WHERE {?s rdf:type imas:Unit; schema:name ?uname; schema:member/imas:nameKana ?nm.}
}
GROUP BY ?uname
HAVING (?c5 = 2 && ?c7 = 1 && ?ce = 0)
ORDER BY ?uname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment