From e171e81f276d44d184e6db203348fcae3523d5d2 Mon Sep 17 00:00:00 2001
From: Alex Yatskov <alex@foosoft.net>
Date: Sun, 18 Sep 2016 11:36:54 -0700
Subject: [PATCH] Group by sense

---
 edict.go | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/edict.go b/edict.go
index e59581e..0aaeb1c 100644
--- a/edict.go
+++ b/edict.go
@@ -36,20 +36,19 @@ func convertEdictEntry(edictEntry jmdict.JmdictEntry) []termSource {
 			return
 		}
 
-		var entry termSource
+		var entryBase termSource
+		entryBase.addTags(reading.Information...)
+		entryBase.addTagsPri(reading.Priorities...)
+
 		if kanji == nil {
-			entry.Expression = reading.Reading
+			entryBase.Expression = reading.Reading
 		} else {
-			entry.Expression = kanji.Expression
-			entry.Reading = reading.Reading
-
-			entry.addTags(kanji.Information...)
-			entry.addTagsPri(kanji.Priorities...)
+			entryBase.Expression = kanji.Expression
+			entryBase.Reading = reading.Reading
+			entryBase.addTags(kanji.Information...)
+			entryBase.addTagsPri(kanji.Priorities...)
 		}
 
-		entry.addTags(reading.Information...)
-		entry.addTagsPri(reading.Priorities...)
-
 		for _, sense := range edictEntry.Sense {
 			if hasString(reading.Reading, sense.RestrictedReadings) {
 				continue
@@ -59,6 +58,9 @@ func convertEdictEntry(edictEntry jmdict.JmdictEntry) []termSource {
 				continue
 			}
 
+			entry := entryBase
+			entry.Tags = append(entry.Tags, entryBase.Tags...)
+
 			for _, glossary := range sense.Glossary {
 				entry.Glossary = append(entry.Glossary, glossary.Content)
 			}
@@ -67,9 +69,9 @@ func convertEdictEntry(edictEntry jmdict.JmdictEntry) []termSource {
 			entry.addTags(sense.Fields...)
 			entry.addTags(sense.Misc...)
 			entry.addTags(sense.Dialects...)
-		}
 
-		entries = append(entries, entry)
+			entries = append(entries, entry)
+		}
 	}
 
 	if len(edictEntry.Kanji) > 0 {