Skip to content

Instantly share code, notes, and snippets.

@yossywolf
Last active February 11, 2017 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yossywolf/e050158f89c27695fd17dc5ab9774d22 to your computer and use it in GitHub Desktop.
Save yossywolf/e050158f89c27695fd17dc5ab9774d22 to your computer and use it in GitHub Desktop.
H.M.P. SPARQL for Sweets

H.M.P. SPARQL for Sweets

はこだてMap+で函館スイーツの情報を得てスイーツな気分になれる SPARQL のクエリー集

URN, 店名, 緯度経度

SPARQL

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX sweets: <http://lod.fun.ac.jp/hakobura/terms/sweet#>

select ?s ?shopname ?lat ?long where {
?s sweets:shopname ?shopname.
?s geo:lat ?lat.
?s geo:long ?long.
FILTER (lang(?shopname) = 'j')
}

Result

{
    "head": {
        "link": [],
        "vars": [
            "s",
            "shopname",
            "lat",
            "long"
        ]
    },
    "results": {
        "distinct": false,
        "ordered": true,
        "bindings": [
            {
                "s": {
                    "type": "uri",
                    "value": "urn:000010"
                },
                "shopname": {
                    "type": "literal",
                    "xml:lang": "j",
                    "value": "パティスリー ジョリクレール"
                },
                "lat": {
                    "type": "literal",
                    "value": "41.821807"
                },
                "long": {
                    "type": "literal",
                    "value": "140.6521807"
                }
            },
            {
                "s": {
                    "type": "uri",
                    "value": "urn:000011"
                },
                "shopname": {
                    "type": "literal",
                    "xml:lang": "j",
                    "value": "たいやき茶屋 北菓り"
                },
                "lat": {
                    "type": "literal",
                    "value": "41.7717568"
                },
                "long": {
                    "type": "literal",
                    "value": "140.7264132"
                }
            },
...

全店舗のID, 店名, 緯度経度

SPARQL

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX sweets: <http://lod.fun.ac.jp/hakobura/terms/sweet#>

select ?id ?shopname ?lat ?long where {
?s sweets:id ?id.
?s sweets:shopname ?shopname.
?s geo:lat ?lat.
?s geo:long ?long.
FILTER (lang(?shopname) = 'j')
}

Result

{
    "head": {
        "link": [],
        "vars": [
            "id",
            "shopname",
            "lat",
            "long"
        ]
    },
    "results": {
        "distinct": false,
        "ordered": true,
        "bindings": [
            {
                "id": {
                    "type": "literal",
                    "value": "000010"
                },
                "shopname": {
                    "type": "literal",
                    "xml:lang": "j",
                    "value": "パティスリー ジョリクレール"
                },
                "lat": {
                    "type": "literal",
                    "value": "41.821807"
                },
                "long": {
                    "type": "literal",
                    "value": "140.6521807"
                }
            },
            {
                "id": {
                    "type": "literal",
                    "value": "000011"
                },
                "shopname": {
                    "type": "literal",
                    "xml:lang": "j",
                    "value": "たいやき茶屋 北菓り"
                },
                "lat": {
                    "type": "literal",
                    "value": "41.7717568"
                },
                "long": {
                    "type": "literal",
                    "value": "140.7264132"
                }
            },
...

店の詳細情報 IDで検索

SPARQL

<urn:000010> のように主語にIDを入れます。

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX schema: <http://schema.org/>
PREFIX sweet: <http://lod.fun.ac.jp/hakobura/terms/sweet#>

SELECT ?shopname ?shopimage ?shopdescription ?area ?modified ?postcode ?address ?telephone ?openingHoursSpecification ?closed ?parking ?eatin ?id ?email ?url ?lat ?long ?featuredproductname ?featuredproductprice ?featuredproductimage ?featuredproductdescription 
WHERE {
<urn:000010> sweet:shopname ?shopname.
<urn:000010> sweet:shopimage ?shopimage.
<urn:000010> sweet:shopdescription ?shopdescription.
<urn:000010> sweet:area ?area.
<urn:000010> dc:modified ?modified.
<urn:000010> sweet:postcode ?postcode.
<urn:000010> schema:address ?address.
<urn:000010> schema:telephone ?telephone.
<urn:000010> schema:openingHoursSpecification ?openingHoursSpecification.
<urn:000010> sweet:closed ?closed.
<urn:000010> sweet:parking ?parking.
<urn:000010> sweet:eatin ?eatin.
<urn:000010> sweet:id ?id.
<urn:000010> schema:email ?email.
<urn:000010> schema:url ?url.
<urn:000010> geo:lat ?lat.
<urn:000010> geo:long ?long.
<urn:000010> sweet:featuredproductname ?featuredproductname.
<urn:000010> sweet:featuredproductprice ?featuredproductprice.
<urn:000010> sweet:featuredproductimage ?featuredproductimage.
<urn:000010> sweet:featuredproductdescription ?featuredproductdescription.
}

Result

店の情報は「漢字」「よみがな」の2つ取得されます
よみがなが要らなかったら FILTER (lang(?shopname) = 'j') をSPARQLのWHEREへ入れましょう。


{
    "head": {
        "link": [],
        "vars": [
            "shopname",
            "shopimage",
            "shopdescription",
            "area",
            "modified",
            "postcode",
            "address",
            "telephone",
            "openingHoursSpecification",
            "closed",
            "parking",
            "eatin",
            "id",
            "email",
            "url",
            "lat",
            "long",
            "featuredproductname",
            "featuredproductprice",
            "featuredproductimage",
            "featuredproductdescription"
        ]
    },
    "results": {
        "distinct": false,
        "ordered": true,
        "bindings": [
            {
                "shopname": {
                    "type": "literal",
                    "xml:lang": "ja-hira",
                    "value": "ぱてぃすりー じょりくれーる"
                },
                "shopimage": {
                    "type": "literal",
                    "value": "http://www.hakodate-sweets.com/pgm/img/main01-20130827040316.jpg"
                },
                "shopdescription": {
                    "type": "literal",
                    "value": "当店は雄大な自然が広がる「北海道・北斗市」にある洋菓子専門店です。パティシエ自慢の季節感・旬感を大事にした創作スイーツを多数取り揃えております。"
                },
                "area": {
                    "type": "literal",
                    "value": "函館市近郊エリア"
                },
                "modified": {
                    "type": "literal",
                    "value": "2016-12-14"
                },
                "postcode": {
                    "type": "literal",
                    "value": "049-0162"
                },
                "address": {
                    "type": "literal",
                    "value": "北斗市中央2-1-5"
                },
                "telephone": {
                    "type": "literal",
                    "value": "0138-73-0370"
                },
                "openingHoursSpecification": {
                    "type": "literal",
                    "value": "0138-73-4013"
                },
                "closed": {
                    "type": "literal",
                    "value": "10:00~20:00"
                },
                "parking": {
                    "type": "literal",
                    "value": "無休"
                },
                "eatin": {
                    "type": "literal",
                    "value": "無料あり"
                },
                "id": {
                    "type": "literal",
                    "value": "000010"
                },
                "email": {
                    "type": "literal",
                    "value": "info@hokuto-jolicreer.com"
                },
                "url": {
                    "type": "literal",
                    "value": "http://www.hokuto-jolicreer.com"
                },
                "lat": {
                    "type": "literal",
                    "value": "41.821807"
                },
                "long": {
                    "type": "literal",
                    "value": "140.6521807"
                },
                "featuredproductname": {
                    "type": "literal",
                    "xml:lang": "ja",
                    "value": "もちもちシュー"
                },
                "featuredproductprice": {
                    "type": "literal",
                    "value": "140円"
                },
                "featuredproductimage": {
                    "type": "literal",
                    "value": "http://www.hakodate-sweets.com/pgm/img/main02-20130827040317.jpg"
                },
                "featuredproductdescription": {
                    "type": "literal",
                    "value": "北斗市産「ふっくりんこ」の米粉を皮に使用したしっとり・もちもちなシュークリームです。持つとずっしりと重さを感じられるくらいにクリームたっぷりと詰めています。"
                }
            },
            {
                "shopname": {
                    "type": "literal",
                    "xml:lang": "j",
                    "value": "パティスリー ジョリクレール"
                },
                "shopimage": {
                    "type": "literal",
                    "value": "http://www.hakodate-sweets.com/pgm/img/main01-20130827040316.jpg"
                },
                "shopdescription": {
                    "type": "literal",
                    "value": "当店は雄大な自然が広がる「北海道・北斗市」にある洋菓子専門店です。パティシエ自慢の季節感・旬感を大事にした創作スイーツを多数取り揃えております。"
                },
                "area": {
                    "type": "literal",
                    "value": "函館市近郊エリア"
                },
                "modified": {
                    "type": "literal",
                    "value": "2016-12-14"
                },
                "postcode": {
                    "type": "literal",
                    "value": "049-0162"
                },
                "address": {
                    "type": "literal",
                    "value": "北斗市中央2-1-5"
                },
                "telephone": {
                    "type": "literal",
                    "value": "0138-73-0370"
                },
                "openingHoursSpecification": {
                    "type": "literal",
                    "value": "0138-73-4013"
                },
                "closed": {
                    "type": "literal",
                    "value": "10:00~20:00"
                },
                "parking": {
                    "type": "literal",
                    "value": "無休"
                },
                "eatin": {
                    "type": "literal",
                    "value": "無料あり"
                },
                "id": {
                    "type": "literal",
                    "value": "000010"
                },
                "email": {
                    "type": "literal",
                    "value": "info@hokuto-jolicreer.com"
                },
                "url": {
                    "type": "literal",
                    "value": "http://www.hokuto-jolicreer.com"
                },
                "lat": {
                    "type": "literal",
                    "value": "41.821807"
                },
                "long": {
                    "type": "literal",
                    "value": "140.6521807"
                },
                "featuredproductname": {
                    "type": "literal",
                    "xml:lang": "ja",
                    "value": "もちもちシュー"
                },
                "featuredproductprice": {
                    "type": "literal",
                    "value": "140円"
                },
                "featuredproductimage": {
                    "type": "literal",
                    "value": "http://www.hakodate-sweets.com/pgm/img/main02-20130827040317.jpg"
                },
                "featuredproductdescription": {
                    "type": "literal",
                    "value": "北斗市産「ふっくりんこ」の米粉を皮に使用したしっとり・もちもちなシュークリームです。持つとずっしりと重さを感じられるくらいにクリームたっぷりと詰めています。"
                }
            }
        ]
    }
}

##店の詳細情報 店名で検索

SPARQL

FILTER regex(?shopname, "たいやき茶屋 北菓り") のように店名を指定します。

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX schema: <http://schema.org/>
PREFIX sweet: <http://lod.fun.ac.jp/hakobura/terms/sweet#>

SELECT ?shopname ?shopimage ?shopdescription ?area ?modified ?postcode ?address ?telephone ?openingHoursSpecification ?closed ?parking ?eatin ?id ?email ?url ?lat ?long ?featuredproductname ?featuredproductprice ?featuredproductimage ?featuredproductdescription 
WHERE {
?s sweet:shopname ?shopname.
?s sweet:shopimage ?shopimage.
?s sweet:shopdescription ?shopdescription.
?s sweet:area ?area.
?s dc:modified ?modified.
?s sweet:postcode ?postcode.
?s schema:address ?address.
?s schema:telephone ?telephone.
?s schema:openingHoursSpecification ?openingHoursSpecification.
?s sweet:closed ?closed.
?s sweet:parking ?parking.
?s sweet:eatin ?eatin.
?s sweet:id ?id.
?s schema:email ?email.
?s schema:url ?url.
?s geo:lat ?lat.
?s geo:long ?long.
?s sweet:featuredproductname ?featuredproductname.
?s sweet:featuredproductprice ?featuredproductprice.
?s sweet:featuredproductimage ?featuredproductimage.
?s sweet:featuredproductdescription ?featuredproductdescription.
FILTER regex(?shopname, "たいやき茶屋 北菓り")
}

Result

店の情報は「漢字」のひとつだけです

{
    "head": {
        "link": [],
        "vars": [
            "shopname",
            "shopimage",
            "shopdescription",
            "area",
            "modified",
            "postcode",
            "address",
            "telephone",
            "openingHoursSpecification",
            "closed",
            "parking",
            "eatin",
            "id",
            "email",
            "url",
            "lat",
            "long",
            "featuredproductname",
            "featuredproductprice",
            "featuredproductimage",
            "featuredproductdescription"
        ]
    },
    "results": {
        "distinct": false,
        "ordered": true,
        "bindings": [
            {
                "shopname": {
                    "type": "literal",
                    "xml:lang": "j",
                    "value": "たいやき茶屋 北菓り"
                },
                "shopimage": {
                    "type": "literal",
                    "value": "http://www.hakodate-sweets.com/pgm/img/main01-20130830040341.jpg"
                },
                "shopdescription": {
                    "type": "literal",
                    "value": "函館朝市内にある、たいやき店。生地の美味しさにこだわり、ハネ付きに仕上げています。定番の甘さ控えめの粒あん等のほか、北海道産のリンゴやじゃがいもを使ったオリジナルのたい焼きが人気です。"
                },
                "area": {
                    "type": "literal",
                    "value": "西部エリア"
                },
                "modified": {
                    "type": "literal",
                    "value": "2016-12-26"
                },
                "postcode": {
                    "type": "literal",
                    "value": "040-0063"
                },
                "address": {
                    "type": "literal",
                    "value": "函館市若松町11-10(函館朝市内)"
                },
                "telephone": {
                    "type": "literal",
                    "value": "0138-84-1998"
                },
                "openingHoursSpecification": {
                    "type": "literal",
                    "value": "10:00~19:00"
                },
                "closed": {
                    "type": "literal",
                    "value": "水曜日(祝日の場合翌日休)"
                },
                "parking": {
                    "type": "literal",
                    "value": "なし"
                },
                "eatin": {
                    "type": "literal",
                    "value": "なし"
                },
                "id": {
                    "type": "literal",
                    "value": "000011"
                },
                "email": {
                    "type": "literal",
                    "value": ""
                },
                "url": {
                    "type": "literal",
                    "value": ""
                },
                "lat": {
                    "type": "literal",
                    "value": "41.7717568"
                },
                "long": {
                    "type": "literal",
                    "value": "140.7264132"
                },
                "featuredproductname": {
                    "type": "literal",
                    "xml:lang": "ja",
                    "value": "りんごとクリームのたい焼き"
                },
                "featuredproductprice": {
                    "type": "literal",
                    "value": "200円"
                },
                "featuredproductimage": {
                    "type": "literal",
                    "value": "http://www.hakodate-sweets.com/pgm/img/main02-20130830040341.jpg"
                },
                "featuredproductdescription": {
                    "type": "literal",
                    "value": "コンポートした北海道産リンゴとカスタードクリームに、シナモンを振りかけて、アップルパイのような味に仕上げました。他に、地物のじゃがいもとチーズを合わせた「じゃがいもとチーズのたい焼(200円)」も人気です。"
                }
            }
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment