From 02c6cf9767820fa16919f2c435768625b8c80df1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 18 Sep 2015 18:19:39 +0900 Subject: [PATCH] Semantics --- build/build.go | 34 +++++++++++++++++++++++----------- build/cache/geocache.json | 4 ++++ build/tabelog.go | 10 ++++++++++ build/tripadvisor.go | 9 +++++++++ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/build/build.go b/build/build.go index 7d6ec10..f2bc5f7 100644 --- a/build/build.go +++ b/build/build.go @@ -53,19 +53,22 @@ func (s scrapeCtx) load(url string) (*goquery.Document, error) { return s.wc.load(url) } +type semantics struct { + accomodating float64 + affordable float64 + atmospheric float64 + delicious float64 +} + type restaurant struct { name string latitude float64 longitude float64 + sem semantics reviews []review - accomodating float64 - affordable float64 - atmospheric float64 - delicious float64 - closestStnName string closestStnDist float64 } @@ -145,7 +148,7 @@ func collateData(reviews []review) map[uint64]*restaurant { return restaurants } -func computeStnData(restaurants map[uint64]*restaurant, stationsPath string) error { +func computeStations(restaurants map[uint64]*restaurant, stationsPath string) error { sq, err := newStationQuery(stationsPath) if err != nil { return err @@ -158,6 +161,12 @@ func computeStnData(restaurants map[uint64]*restaurant, stationsPath string) err return nil } +func computeSemantics(restaraunts map[uint64]*restaurant) { + type definer interface { + define(keyword string) semantics + } +} + func dumpData(dbPath string, restaraunts map[uint64]*restaurant) error { db, err := sql.Open("sqlite3", dbPath) if err != nil { @@ -208,10 +217,10 @@ func dumpData(dbPath string, restaraunts map[uint64]*restaurant) error { ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, rest.name, strings.Join(urls, ","), - rest.delicious, - rest.accomodating, - rest.affordable, - rest.atmospheric, + rest.sem.delicious, + rest.sem.accomodating, + rest.sem.affordable, + rest.sem.atmospheric, rest.latitude, rest.longitude, rest.closestStnDist, @@ -284,8 +293,11 @@ func main() { log.Print(color.BlueString("collating data...")) restaurants := collateData(reviews) + log.Print(color.BlueString("computing data semantics..")) + computeSemantics(restaurants) + log.Print(color.BlueString("computing station data...")) - if err := computeStnData(restaurants, *stationsPath); err != nil { + if err := computeStations(restaurants, *stationsPath); err != nil { log.Fatal(err) } diff --git a/build/cache/geocache.json b/build/cache/geocache.json index 5256c0d..22e5a2c 100644 --- a/build/cache/geocache.json +++ b/build/cache/geocache.json @@ -27,6 +27,10 @@ "Latitude": 35.5252002, "Longitude": 139.6930519 }, + "1,396,279,436": { + "Latitude": 39.886922, + "Longitude": 32.8780643 + }, "1-1 Akebonocho Naka-ku Yokohama Kanagawa": { "Latitude": 35.4419997, "Longitude": 139.6302873 diff --git a/build/tabelog.go b/build/tabelog.go index 690b9b1..da9ec0a 100644 --- a/build/tabelog.go +++ b/build/tabelog.go @@ -35,6 +35,16 @@ type tabelog struct { scrapeCtx } +func (tabelog) define(keyword string) semantics { + return map[string]semantics{ + "dishes": {accomodating: 0.0, affordable: 0.0, atmospheric: 0.0, delicious: 0.8}, + "drinks": {accomodating: 0.0, affordable: 0.0, atmospheric: 0.0, delicious: 0.2}, + "service": {accomodating: 1.0, affordable: 0.0, atmospheric: 0.0, delicious: 0.0}, + "cost": {accomodating: 0.0, affordable: 1.0, atmospheric: 0.0, delicious: 0.0}, + "atmosphere": {accomodating: 0.0, affordable: 0.0, atmospheric: 1.0, delicious: 0.0}, + }[keyword] +} + func (tabelog) index(doc *goquery.Document) (string, []string) { var reviewUrls []string doc.Find("div.list-rst__header > p > a").Each(func(index int, sel *goquery.Selection) { diff --git a/build/tripadvisor.go b/build/tripadvisor.go index 8194049..21d6b57 100644 --- a/build/tripadvisor.go +++ b/build/tripadvisor.go @@ -35,6 +35,15 @@ type tripadvisor struct { scrapeCtx } +func (tripadvisor) define(keyword string) semantics { + return map[string]semantics{ + "food": {accomodating: 0.0, affordable: 0.0, atmospheric: 0.0, delicious: 1.0}, + "service": {accomodating: 1.0, affordable: 0.0, atmospheric: 0.0, delicious: 0.0}, + "value": {accomodating: 0.0, affordable: 1.0, atmospheric: 0.0, delicious: 0.0}, + "atmosphere": {accomodating: 0.0, affordable: 0.0, atmospheric: 1.0, delicious: 0.0}, + }[keyword] +} + func (tripadvisor) index(doc *goquery.Document) (string, []string) { var reviewUrls []string doc.Find("a.property_title").Each(func(index int, sel *goquery.Selection) {