Fix race conditions in morpho handling

Change-Id: If45e00dbaf9741eff1c5743d5742ad047031131a
diff --git a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
index d95dd60..57f14f6 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
@@ -15,6 +15,7 @@
 import org.xml.sax.InputSource
 import java.io.File
 import java.io.InputStreamReader
+import java.util.HashMap
 import java.util.logging.Logger
 
 class KorapXml2Conllu {
@@ -115,14 +116,14 @@
 
                                 "morpho.xml" -> {
                                     val fsSpans: NodeList = doc.getElementsByTagName("span")
-                                    extractMorphoSpans(fsSpans, docId, morpho)
+                                    morpho[docId] = extractMorphoSpans(fsSpans)
                                 }
                             }
                             if (texts[docId] != null && sentences[docId] != null && tokens[docId] != null
                                 && (!waitForMorpho || morpho[docId] != null)
                             ) {
                                 synchronized(System.out) {
-                                    println("# foundry = base")
+                                    println("# foundry = $foundry")
                                     println("# filename = ${fname[docId]}")
                                     println("# text_id = $docId")
                                     printTokenOffsetsInSentence(
@@ -241,10 +242,9 @@
     }
 
     private fun extractMorphoSpans(
-        fsSpans: NodeList,
-        docId: String,
-        morpho: ConcurrentHashMap<String, MutableMap<String, MorphoSpan>>
-    ) {
+        fsSpans: NodeList
+    ): MutableMap<String, MorphoSpan> {
+        val res: MutableMap<String, MorphoSpan> = HashMap()
         IntStream.range(0, fsSpans.length)
             .mapToObj(fsSpans::item)
             .forEach { node ->
@@ -263,11 +263,9 @@
                             "certainty" -> fs.misc = value
                         }
                     }
-                if (morpho[docId] == null) {
-                    morpho[docId] = mutableMapOf()
-                }
-                morpho[docId]!![fromTo] = fs
+                res[fromTo] = fs
             }
+        return res
     }
 
     private fun extractSentenceSpans(spans: NodeList): Array<Span> {