amuse.git

commit f63b623ec5f086cc7a4e0923ae7e35055f2bfc44

Author: Adam <git@apiote.tk>

show book and bookserie native title if label is empty

 wikidata/book.go | 9 +++++++--
 wikidata/bookserie.go | 16 +++++++++++++---


diff --git a/wikidata/book.go b/wikidata/book.go
index 02eca1ff6577ec97fa32c55695ce30c2972a9463..c35dc9da603a6a6eb87c6550055fb3dfa042848d 100644
--- a/wikidata/book.go
+++ b/wikidata/book.go
@@ -60,8 +60,9 @@ 	id := args[0].(*network.Request).Id
 	tag := args[0].(*network.Request).Language[:2]
 	result := args[1].(*Result)
 	repo := result.Repo
-	res, err := repo.Query(`SELECT ?bookLabel ?authorLabel ?series ?seriesLabel ?ordinal ?genreLabel (YEAR(?publication) AS ?year) ?article_title WHERE {
+	res, err := repo.Query(`SELECT ?title ?bookLabel ?authorLabel ?series ?seriesLabel ?ordinal ?genreLabel (YEAR(?publication) AS ?year) ?article_title WHERE {
   ` + id + ` wdt:P50 ?author.
+  ` + id + ` wdt:P1476 ?title.
   optional {
     ` + id + ` wdt:P577 ?publication.
   }
@@ -112,11 +113,15 @@ 		bookId := id
 		if result["book"].Value != "" {
 			bookId = strings.Replace(result["book"].Value, "http://www.wikidata.org/entity/", "wd:", 1)
 		}
+		title := result["bookLabel"].Value
+		if title == strings.Replace(bookId, "wd:", "", 1) || title == "" {
+			title = result["title"].Value
+		}
 		book := datastructure.Book{
 			Id:          bookId,
 			Uri:         "/books/" + bookId,
 			Source:      []datastructure.Source{},
-			Title:       result["bookLabel"].Value,
+			Title:       title,
 			Year:        year,
 			SerieUri:    strings.Replace(result["series"].Value, "http://www.wikidata.org/entity/", "/bookseries/wd:", 1),
 			SerieName:   result["seriesLabel"].Value,




diff --git a/wikidata/bookserie.go b/wikidata/bookserie.go
index 297f8f3feb1ef02b149f9b44abd10b982d87a8ae..f9ef0f49ef54f80fbdd9aea22e02a6a05bd5fe28 100644
--- a/wikidata/bookserie.go
+++ b/wikidata/bookserie.go
@@ -68,9 +68,11 @@ 	id := args[0].(*network.Request).Id
 	tag := args[0].(*network.Request).Language[:2]
 	result := args[1].(*Result)
 	repo := result.Repo
-	res, err := repo.Query(`SELECT ?seriesLabel ?genreLabel ?authorLabel ?partLabel ?part ?article_title WHERE {
+	res, err := repo.Query(`SELECT ?title ?seriesLabel ?genreLabel ?authorLabel ?partLabel ?partTitle ?part ?article_title WHERE {
   ` + id + ` wdt:P50 ?author;
+             wdt:P1476 ?title;
              wdt:P527 ?part.
+  ?part wdt:P1476 ?partTitle.
   OPTIONAL {
     ` + id + ` wdt:P136 ?genre.
   }
@@ -102,8 +104,12 @@ 	} else {
 		authors := map[string]bool{}
 		genres := map[string]bool{}
 		result := res.Results.Bindings[0]
+		title := result["bookLabel"].Value
+		if title == strings.Replace(id, "wd:", "", 1) || title == "" {
+			title = result["title"].Value
+		}
 		bookSerie := BookSerie{
-			Title:   result["seriesLabel"].Value,
+			Title:   title,
 			Source:  []datastructure.Source{},
 			Authors: []string{},
 			Genres:  []string{},
@@ -115,10 +121,14 @@ 			authors[r["authorLabel"].Value] = true
 			if r["genreLabel"].Value != "" {
 				genres[r["genreLabel"].Value] = true
 			}
+			title := r["partLabel"].Value
+			if title == strings.Replace(r["part"].Value, "http://www.wikidata.org/entity/", "", 1) || title == "" {
+				title = r["partTitle"].Value
+			}
 			partId := strings.Replace(r["part"].Value, "http://www.wikidata.org/entity/", "", 1)
 			bookSerie.Parts[partId] = BookSeriePart{
 				Uri:   strings.Replace(r["part"].Value, "http://www.wikidata.org/entity/", "/books/wd:", 1),
-				Title: r["partLabel"].Value,
+				Title: title,
 			}
 		}
 		bookSerie.Source = append(bookSerie.Source, datastructure.Source{