Skip to content

subroh0508/otonashi

Repository files navigation

Otonashi

Download Kotori-rate

Otonashi is a SPARQL client library made by Kotlin.

features

Install

repositories {
    jcenter()
    // or maven { url 'https://dl.bintray.com/subroh0508/maven' }
}

dependencies {
    implementation 'net.subroh0508.otonashi:core:${latest_version}'
    
    // additional
    implementation 'net.subroh0508.otonashi.vocabularies:schema:${latest_version}'
    implementation 'net.subroh0508.otonashi.vocabularies:foaf:${latest_version}'
    implementation 'net.subroh0508.otonashi.vocabularies:imasparql:${latest_version}'
}

Usage

Sample query is

SELECT
  (replace(str(?s), 'https:\/\/sparql.crssnky.xyz\/imasrdf\/RDFs\/detail\/', '') as ?id)
  ?name
  (concat('[',group_concat(?unit_name;separator=','),']') as ?unit_names)
WHERE {
  ?s rdf:type imas:Idol;
     schema:name ?name;
     imas:Title ?title;
     schema:memberOf ?unit_url
  filter(contains(?title, 'CinderellaGirls')).
  ?unit_url rdf:type imas:Unit;
    schema:name ?unit_name.
} group by ?s ?name

Use by Otonashi

// initialize client
// note: requires schema, foaf and imasparql vocabularies
val kotori: Kotori by lazy {
    Otonashi.Study {
        destination("https://sparql.crssnky.xyz/spql/imas/query")
        reminds(SchemaPrefix.SCHEMA, FoafPrefix.FOAF, ImasparqlPrefix.IMAS)
        buildsUp(*schemaVocabularies, *foafVocabularies, *imasparqlVocabularies)
    }
}

// build query
val query = kotori.where {
    v("s") be {
        rdfP.type to imasC.idol and
        schemaP.name to v("name") and
        imasP.title to v("title") and
        schemaP.memberOf to v("unit_url")
    }
    filter {
        contains(v("title"), "CinderellaGirls")
    }
    v("unit_url") be {
        rdfP.type to imasC.unit and
        schemaP.name to v("unit_name")
    }
}.select {
    replace(
        str(v("s")),
        """https://sparql.crssnky.xyz/imasrdf/RDFs/detail/""",
        ""
    ) `as` v("id")
    groupConcat(v("unit_name"), ",") `as` v("unit_names")

    + v("id") + v("name") + v("unit_names")
}.groupBy { + v("s") + v("name") }

print(query.toString()) // => "SELECT (replace(..."

Special Thanks

im@sparql: https://github.com/imas/imasparql

License

This project is licensed under the terms of the MIT license.