Last active
February 11, 2018 22:02
-
-
Save mkock/4b7e0a6dca0d6e0ba178c171790ee9b2 to your computer and use it in GitHub Desktop.
Concurrent version of the DMR string parser in Go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ParseExcerpt runs the string parser. | |
func (p *StringParser) ParseExcerpt(id int, lines <-chan []string, parsed chan<- string, done chan<- int) { | |
var isCar bool | |
csv, brand, model := "", "", "" | |
proc := 0 // How many excerpts did we process? | |
for excerpt := range lines { | |
for _, line := range excerpt { | |
if strings.HasPrefix(line, "<ns:KoeretoejArtNummer>") { | |
isCar = strings.HasPrefix(line, "<ns:KoeretoejArtNummer>1<") | |
continue | |
} | |
if isCar { | |
if strings.HasPrefix(line, "<ns:KoeretoejMaerkeTypeNavn>") { | |
brand = getXMLVal(line) | |
} else if strings.HasPrefix(line, "<ns:KoeretoejModelTypeNavn>") { | |
model = getXMLVal(line) | |
} | |
if brand != "" && model != "" { | |
csv = fmt.Sprintf("%v;%v", brand, model) | |
parsed <- csv | |
proc++ | |
brand, model = "", "" | |
} | |
} | |
} | |
} | |
fmt.Printf("String-worker %d finished after processing %d excerpts\n", id, proc) | |
done <- id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment