Extract foundry

Change-Id: I67fca2e03782effb1a7a3eea9cfa897c4e98c286
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 57f14f6..b5b47b7 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXml2Conllu.kt
@@ -50,6 +50,7 @@
                     tokens,
                     fnames,
                     morpho,
+                    getFoundryFromZipFileNames(zips),
                     zips.size > 1
                 )
             }
@@ -63,6 +64,23 @@
         // Further processing as needed
     }
 
+    private fun getFoundryFromZipFileName(zipFileName: String): String {
+        if (!zipFileName.matches(Regex(".*\\.([^/.]+)\\.zip$"))) {
+            return "base"
+        }
+        return zipFileName.replace(Regex(".*\\.([^/.]+)\\.zip$"), "$1")
+    }
+
+    private fun getFoundryFromZipFileNames(zipFileNames: Array<String?>): String {
+        for (zipFileName in zipFileNames) {
+            val foundry = getFoundryFromZipFileName(zipFileName!!)
+            if (foundry != "base") {
+                return foundry
+            }
+        }
+        return "base"
+    }
+
     private fun processZipFile(
         zipFilePath: String,
         texts: ConcurrentHashMap<String, String>,
@@ -70,7 +88,8 @@
         tokens: ConcurrentHashMap<String, Array<Span>>,
         fname: ConcurrentHashMap<String, String>,
         morpho: ConcurrentHashMap<String, MutableMap<String, MorphoSpan>>,
-        waitForMorpho: Boolean = false
+        foundry: String = "base",
+        waitForMorpho: Boolean = false,
     ) {
         try {
             ZipFile(zipFilePath).use { zipFile ->
diff --git a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KorapXml2ConlluTest.kt b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KorapXml2ConlluTest.kt
index cba0135..8142f67 100644
--- a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KorapXml2ConlluTest.kt
+++ b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KorapXml2ConlluTest.kt
@@ -7,7 +7,7 @@
 import java.net.URL
 import kotlin.test.Test
 import kotlin.test.assertContains
-import de.ids_mannheim.korapxmltools.KorapXml2Conllu
+import org.junit.Ignore
 
 class KorapXml2ConlluTest {
     private val outContent = ByteArrayOutputStream(10000000)
@@ -44,6 +44,10 @@
         classUnderTest.main(args)
         assertContains(
             outContent.toString(),
+            "# foundry = base"
+        )
+        assertContains(
+            outContent.toString(),
             "# start_offsets = 55 55 59 63 70 75 82 87 94 102 105 111 120 124 130 134 140 144 151 153 163 175 187 191 207 209 213 218 222 239 248 255 259 264 267 271 277 283 297 307"
         )
     }
@@ -54,6 +58,10 @@
         classUnderTest.main(args)
         assertContains(
             outContent.toString(),
+            "# foundry = tree_tagger"
+        )
+        assertContains(
+            outContent.toString(),
             "9\tentzücke\tentzücken\t_\tVVFIN\t_\t_\t_\t_\t1.000000"
         )
     }
@@ -64,6 +72,10 @@
         classUnderTest.main(args)
         assertContains(
             outContent.toString(),
+            "# foundry = tree_tagger"
+        )
+        assertContains(
+            outContent.toString(),
             "9\tentzücke\tentzücken\t_\tVVFIN\t_\t_\t_\t_\t1.000000"
         )
     }
@@ -76,11 +88,15 @@
         classUnderTest.main(args)
         assertContains(
             outContent.toString(),
+            "# foundry = tree_tagger"
+        )
+        assertContains(
+            outContent.toString(),
             "30\tvraie\tvrai\t_\tADJ\t_\t_\t_\t_\t1.000000"
         )
     }
 
-    @Suppress("for some reason not working")
+    @Ignore("for some reason not working")
     fun canConvertMorphoFeatureAnnotations() {
         val classUnderTest = KorapXml2Conllu()
         val args = arrayOf(goe, goeMarmot)