Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlinでクエリ言語のクライアントを作った話

 Kotlinでクエリ言語のクライアントを作った話

集まれKotlin好き!Kotlin愛好会 vol.10のLT資料です

https://love-kotlin.connpass.com/event/124099/

Otonashi: https://github.com/subroh0508/otonashi

subroh_0508

April 25, 2019
Tweet

More Decks by subroh_0508

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ w ʹ͜͠Γ͞ͿΖʙ w גࣜձࣾ#FBS5BJM w "OESPJEΤϯδχΞ ,PUMJO+BWB ˑ w

    8FCΤϯδχΞ 3BJMT3FBDU  w ,PUMJOྺ໿೥ ೥݄ʙ  w झຯͰαʔόαΠυɺ,PUMJO+4 5XJUUFS*%!TVCSPI@
  2. ࣮ࡍͷΫΤϦ w ೔ຊͷ౎ಓ෎ݝ໊ͱ8JLJQFEJBͷΞϒετϥΫτΛऔಘ select ?pref_name ?abstract where { ?pref rdf:type

    schema:AdministrativeArea; dbo:country ?country; rdfs:label ?pref_name; dbo:abstract ?abstract. filter( contains(str(?country), "日本") ) } ݁Ռ ੜΫΤϦ
  3. ੡࡞ͷϞνϕʔγϣϯ w ༷ʑͳΤϯυϙΠϯτ͕ଘࡏ w ࠃཱࠃձਤॻؗͷయڌσʔλ IUUQJEOEMHPKQJOGPSNBUJPOTQBSRM  w ژ౎ࢢͷࢪઃσʔλ IUUQTTQBSRMDJUZLZPUPMHKQTQBSRM

     w JN!TQBSRM IUUQTTQBSRMDSTTOLZYZ[JNBT ৭ʑͳΤϯυϙΠϯτ͕͋ͬͯ໘നͦ͏ "DUJWF3FDPSEͬΆ͘ΧδϡΞϧʹΫΤϦୟ͚ͨΒָͦ͠͏ ͱ͍͏͔JN!TQBSRMͰແݶʹ༡ͼ͍ͨ ຊԻ ˞ΞΠυϧϚελʔͷΩϟϥΫλʔɾָۂɾ୆ࢺ౳ͷσʔλ
  4. 0WFSWJFX w ೔ຊͷ౎ಓ෎ݝ໊ͱ8JLJQFEJBͷΞϒετϥΫτΛऔಘ select ?pref_name ?abstract where { ?pref rdf:type

    schema:AdministrativeArea; dbo:country ?country; rdfs:label ?pref_name; dbo:abstract ?abstract. filter( contains(str(?country), "日本") ) } ੜΫΤϦ client.where { v("pref") be { rdfP.type to schemaC.administrativeArea and iri("dbo:country") to v("country") and rdfsP.label to v("pref_name") and iri("dbo:abstract") to v("abstract") } filter { contains(str(v("country")), "日本") } }.select { + v("pref_name") + v("abstract") } 0UPOBTIJ
  5. ࣮૷ղઆ w 5SJQMFͷදݱ w ओޠɾड़ޠɾ໨తޠͰߏ੒͞ΕΔʮτϦϓϧɾύλʔϯʯ ?pref rdf:type schema:AdministrativeArea. v("pref") be

    { rdfP.type to schemaC.administrativeArea } ओޠ ड़ޠ ໨తޠ ओޠ ड़ޠ ໨తޠ JOpYؔ਺
  6. ࣮૷ͨؔ͠਺ infix fun TripleItem.be(pattern: TriplePattern.() -> Unit): GraphPattern { patterns.add(TriplePattern(this,

    vocabulary).apply(pattern)) return this@GraphPattern } infix fun TripleItem.to(`object`: TripleItem): Triple<TripleItem, TripleItem, TripleItem> { triples.addAll(listOf(Triples(subject, this, `object`), Period)) return Triple(subject, this, `object`) } CFؔ਺ (SBQI1BUUFSOΫϥε಺ UPؔ਺ 5SJQMF1BUUFSOΫϥε಺
  7. ࣮૷ͨؔ͠਺ infix fun TripleItem.be(pattern: TriplePattern.() -> Unit): GraphPattern { patterns.add(TriplePattern(this,

    vocabulary).apply(pattern)) return this@GraphPattern } infix fun TripleItem.to(`object`: TripleItem): Triple<TripleItem, TripleItem, TripleItem> { triples.addAll(listOf(Triples(subject, this, `object`), Period)) return Triple(subject, this, `object`) } CFؔ਺ (SBQI1BUUFSOΫϥε಺ UPؔ਺ 5SJQMF1BUUFSOΫϥε಺
  8. ࣮૷ͨؔ͠਺ infix fun TripleItem.be(pattern: TriplePattern.() -> Unit): GraphPattern { patterns.add(TriplePattern(this,

    vocabulary).apply(pattern)) return this@GraphPattern } infix fun TripleItem.to(`object`: TripleItem): Triple<TripleItem, TripleItem, TripleItem> { triples.addAll(listOf(Triples(subject, this, `object`), Period)) return Triple(subject, this, `object`) } CFؔ਺ (SBQI1BUUFSOΫϥε಺ UPؔ਺ 5SJQMF1BUUFSOΫϥε಺
  9. ࣮૷ͨؔ͠਺ infix fun TripleItem.be(pattern: TriplePattern.() -> Unit): GraphPattern { patterns.add(TriplePattern(this,

    vocabulary).apply(pattern)) return this@GraphPattern } infix fun TripleItem.to(`object`: TripleItem): Triple<TripleItem, TripleItem, TripleItem> { triples.addAll(listOf(Triples(subject, this, `object`), Period)) return Triple(subject, this, `object`) } CFؔ਺ (SBQI1BUUFSOΫϥε಺ UPؔ਺ 5SJQMF1BUUFSOΫϥε಺
  10. ࣮૷ղઆ w 5SJQMFͷදݱ w ओޠɾड़ޠɾ໨తޠͰߏ੒͞ΕΔʮτϦϓϧɾύλʔϯʯ ?pref rdf:type schema:AdministrativeArea. v("pref") be

    { rdfP.type to schemaC.administrativeArea } ओޠ ड़ޠ ໨తޠ ओޠ ड़ޠ ໨తޠ ϥϜμࣜ
  11. ϥϜμࣜ w ؔ਺Λએݴͤͣɺͦͷ৔Ͱม਺ͷΑ͏ʹ౉͢ w ؔ਺ͷϨγʔόʔΛ ࢦఆ͢Δ͜ͱ΋Մೳ class HTML { fun

    body() { ... } } fun html(init: HTML.() -> Unit): HTML { val html = HTML() html.init() return html } html { // レシーバ付きラムダがここから始まる body() // レシーバオブジェクトのメソッドを呼んでいる }
  12. ϥϜμࣜ w ؔ਺Λએݴͤͣɺͦͷ৔Ͱม਺ͷΑ͏ʹ౉͢ w ؔ਺ͷϨγʔόʔΛ ࢦఆ͢Δ͜ͱ΋Մೳ class HTML { fun

    body() { ... } } fun html(init: HTML.() -> Unit): HTML { val html = HTML() html.init() return html } html { // レシーバ付きラムダがここから始まる body() // レシーバオブジェクトのメソッドを呼んでいる } Ϩγʔόʔ෇ϥϜμࣜ ˠϨγʔόʔʹ)5.-ΫϥεΛࢦఆ
  13. ϥϜμࣜ w ؔ਺Λએݴͤͣɺͦͷ৔Ͱม਺ͷΑ͏ʹ౉͢ w ؔ਺ͷϨγʔόʔΛ ࢦఆ͢Δ͜ͱ΋Մೳ class HTML { fun

    body() { ... } } fun html(init: HTML.() -> Unit): HTML { val html = HTML() html.init() return html } html { // レシーバ付きラムダがここから始まる body() // レシーバオブジェクトのメソッドを呼んでいる } )5.-ܕΠϯελϯεੜ੒ ˠϨγʔόʔࢦఆɺ࣮ߦ
  14. ϥϜμࣜ w ؔ਺Λએݴͤͣɺͦͷ৔Ͱม਺ͷΑ͏ʹ౉͢ w ؔ਺ͷϨγʔόʔΛ ࢦఆ͢Δ͜ͱ΋Մೳ class HTML { fun

    body() { ... } } fun html(init: HTML.() -> Unit): HTML { val html = HTML() html.init() return html } html { // レシーバ付きラムダがここから始まる body() // レシーバオブジェクトのメソッドを呼んでいる } JOJU͕࣮ࡍʹ࣮ߦ͞Ε͍ͯΔͱ͜Ζ ˠதׅހJOJUͷॲཧ ˠதׅހͷதͷUIJT͸)5.-Ϋϥε ɹʹͳΔ
  15. ࣮૷ղઆ w ͳͥϥϜμࣜΛ࢖͏ͷ͔ w ϥϜμࣜΛ࢖Θͳ͍৔߹ w CF΋UP΋5SJQMF*UFNΫϥεಉ࢜Λͭͳ͙JOpYؔ਺ ˠແݶʹܨ͛ΒΕͯ͠·͏ʂɹߏจΤϥʔ͕࣮ߦ͢Δ·Ͱ෼͔Βͳ͍ʂ v("pref") be

    rdfP.type be schemaC.administrativeArea be … v("pref") to rdfP.type to schemaC.administrativeArea to … v("pref") be { rdfP.type to schemaC.administrativeArea }
  16. ࣮૷ղઆ w ϥϜμࣜΛ࢖ͬͨ৔߹ w CFؔ਺ˠ(SBQI1BUUFSOΫϥε಺ʹ࣮૷ɺҾ਺͸5SJQMF1BUUFSO 6OJU w UPؔ਺ˠ5SJQMF1BUUFSOΫϥε಺ʹ࣮૷ infix fun

    TripleItem.be(pattern: TriplePattern.() -> Unit): GraphPattern { patterns.add(TriplePattern(this, vocabulary).apply(pattern)) return this@GraphPattern } ʜCF\ʜUPʜ^ͱ͔͠ॻ͚ͳ͍Α͏ʹڧ੍ʂ ΫΤϦΛୟ͘·Ͱ෼͔Βͳ͔ͬͨߏจΤϥʔ͕࣮ߦલʹ෼͔Δʂ
  17. ·ͱΊ w ,PUMJOͰ41"32-ΫϥΠΞϯτΛ࣮૷ͨ͠ w ύζϧͬΆָ͍ͯ͘͠ʂ w ීஈ͋·Γ৮Βͳ͍,PUMJOͷݴޠ࢓༷Λ༗ޮʹ׆༻Ͱ͖ͯ໘ന͍ʂ w ϓϩμΫτʹ׆͔͢ʹ͸ w

    αʔόʔαΠυ,PUMJOͰෳࡶͳݕࡧΫΤϦΛؾ࣋ͪΑ͘ॻ͖͍ͨ࣌ w ۀ຿ϩδοΫʹϢʔβʔ͕ΧελϜՄೳͳܭࢉ͕ࣜݱΕΔ࣌ ྫฐࣾͷܦඅਫ਼ࢉαʔϏεͷ೔౰ܭࢉࣜ