Fix build warnings
Change-Id: I3380441ab6f0b799eb696a7dac3153fabb703932
diff --git a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt
index b039795..e6da81e 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/KorapXmlTool.kt
@@ -1648,7 +1648,7 @@
} else {
LOGGER.info("Processing zip files sequentially")
Arrays.stream(zips).forEachOrdered { zipFilePath ->
- processZipFileSequentially((zipFilePath ?: "").toString(), getFoundryFromZipFileNames(zips))
+ processZipFileSequentially(zipFilePath, getFoundryFromZipFileNames(zips))
}
}
@@ -3405,7 +3405,7 @@
}
if (outputFormat == OutputFormat.KRILL) {
- processedTextsPerZip.getOrPut(zipPath.toString()) { mutableSetOf() }.add(docId)
+ processedTextsPerZip.getOrPut(zipPath) { mutableSetOf() }.add(docId)
}
val effectiveWaitForMorpho = if (fileName == "morpho.xml") true else waitForMorpho
@@ -4485,7 +4485,7 @@
XMLStreamConstants.END_ELEMENT -> {
if (reader.localName == "span") {
if (isSentence && currentFrom != null && currentTo != null) {
- list.add(Span(currentFrom!!, currentTo!!))
+ list.add(Span(currentFrom, currentTo))
}
currentFrom = null
currentTo = null
@@ -4594,7 +4594,7 @@
line.isEmpty() -> {
// Sentence boundary: record the sentence span if available
if (sentenceStartOffset != null && sentenceEndOffset != null) {
- sentenceSpans.add(Span(sentenceStartOffset!!, sentenceEndOffset!!))
+ sentenceSpans.add(Span(sentenceStartOffset, sentenceEndOffset))
}
sentenceStartOffset = null
sentenceEndOffset = null
@@ -4639,7 +4639,7 @@
// If last sentence did not end with an empty line, capture it now
if (sentenceStartOffset != null && sentenceEndOffset != null) {
- sentenceSpans.add(Span(sentenceStartOffset!!, sentenceEndOffset!!))
+ sentenceSpans.add(Span(sentenceStartOffset, sentenceEndOffset))
}
if (morphoSpans.isEmpty()) {
@@ -4839,7 +4839,7 @@
// Add final document
if (currentTextId != null && currentFoundry != null && currentLines.isNotEmpty()) {
- documents.add(ConlluDocument(currentTextId!!, currentFoundry!!, currentLines.toList()))
+ documents.add(ConlluDocument(currentTextId, currentFoundry, currentLines.toList()))
}
if (documents.isEmpty()) {
@@ -4899,7 +4899,7 @@
line.isEmpty() -> {
// Sentence boundary
if (sentenceStartOffset != null && sentenceEndOffset != null) {
- sentenceSpans.add(Span(sentenceStartOffset!!, sentenceEndOffset!!))
+ sentenceSpans.add(Span(sentenceStartOffset, sentenceEndOffset))
}
sentenceStartOffset = null
sentenceEndOffset = null
@@ -4957,7 +4957,7 @@
// Capture final sentence if not ended with empty line
if (sentenceStartOffset != null && sentenceEndOffset != null) {
- sentenceSpans.add(Span(sentenceStartOffset!!, sentenceEndOffset!!))
+ sentenceSpans.add(Span(sentenceStartOffset, sentenceEndOffset))
}
if (morphoSpans.isEmpty()) {
@@ -5449,7 +5449,7 @@
}
}
if (year != null && month != null && day != null) {
- metadata["pubDate"] = "${year}-${month!!.padStart(2, '0')}-${day!!.padStart(2, '0')}"
+ metadata["pubDate"] = "${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}"
}
headerRoot.firstElement("ref") { it.getAttribute("type") == "page_url" }
@@ -5867,7 +5867,7 @@
is String -> currentValue.isBlank()
else -> false
}
- if (shouldInherit && value != null) {
+ if (shouldInherit) {
when (value) {
is String -> if (value.isNotBlank()) textData.headerMetadata[key] = value
is List<*> -> if (value.isNotEmpty()) textData.headerMetadata[key] = value
@@ -5884,7 +5884,7 @@
is String -> currentValue.isBlank()
else -> false
}
- if (shouldInherit && value != null) {
+ if (shouldInherit) {
when (value) {
is String -> if (value.isNotBlank()) textData.headerMetadata[key] = value
is List<*> -> if (value.isNotEmpty()) textData.headerMetadata[key] = value
diff --git a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/OpenNlpBridge.kt b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/OpenNlpBridge.kt
index ed435d1..3ade1c2 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/OpenNlpBridge.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/OpenNlpBridge.kt
@@ -21,7 +21,7 @@
synchronized(model) {
if (POSmodel == null) {
logger.info("Initializing OpenNLP with model $model")
- POSmodel = POSModel(File(model as String).inputStream())
+ POSmodel = POSModel(File(model).inputStream())
logger.info("Model $model loaded")
}
}
@@ -48,4 +48,4 @@
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/formatters/KorapXmlFormatter.kt b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/formatters/KorapXmlFormatter.kt
index ec9a5aa..55c08b3 100644
--- a/app/src/main/kotlin/de/ids_mannheim/korapxmltools/formatters/KorapXmlFormatter.kt
+++ b/app/src/main/kotlin/de/ids_mannheim/korapxmltools/formatters/KorapXmlFormatter.kt
@@ -159,7 +159,7 @@
val sortedKeys = context.morpho?.keys?.sortedBy { it.split("-")[0].toInt() }
sortedKeys?.forEach { spanString ->
- val mfs = context.morpho?.get(spanString)
+ val mfs = context.morpho[spanString]
val offsets = spanString.split("-")
if(offsets.size != 2) {
LOGGER.warning("Invalid span: $spanString in ${context.docId}")
diff --git a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/ConlluConversionTest.kt b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/ConlluConversionTest.kt
index fc6f806..7b9aa65 100644
--- a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/ConlluConversionTest.kt
+++ b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/ConlluConversionTest.kt
@@ -402,7 +402,7 @@
val filenameLine = lines.find { it.startsWith("# filename = ") }
assertNotNull(filenameLine, "Should have filename comment line")
assertTrue(
- filenameLine!!.contains("/spacy/morpho.xml"),
+ filenameLine.contains("/spacy/morpho.xml"),
"Filename should point to spacy/morpho.xml, but was: $filenameLine"
)
assertFalse(
@@ -458,4 +458,4 @@
outputDir.deleteRecursively()
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/SparseAnnotationExternalTest.kt b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/SparseAnnotationExternalTest.kt
index f6fd655..e853ef2 100644
--- a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/SparseAnnotationExternalTest.kt
+++ b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/SparseAnnotationExternalTest.kt
@@ -10,13 +10,17 @@
class SparseAnnotationExternalTest {
private fun extractFileFromZip(zipFile: File, regex: Regex): String? {
- val zip = org.apache.commons.compress.archivers.zip.ZipFile(zipFile)
- val entry = zip.entries.asSequence().firstOrNull { regex.matches(it.name) }
- return if (entry != null) {
- zip.getInputStream(entry).bufferedReader().use { it.readText() }
- } else {
- null
- }
+ return org.apache.commons.compress.archivers.zip.ZipFile.builder()
+ .setFile(zipFile)
+ .get()
+ .use { zip ->
+ val entry = zip.entries.asSequence().firstOrNull { regex.matches(it.name) }
+ if (entry != null) {
+ zip.getInputStream(entry).bufferedReader().use { it.readText() }
+ } else {
+ null
+ }
+ }
}
@Test
@@ -66,7 +70,7 @@
// Verify that the annotation is on the correct span (32-34)
// Note: Attribute order is not guaranteed, so check for attributes individually
assertTrue(
- morphoXml!!.contains("""from="32"""") && morphoXml.contains("""to="34""""),
+ morphoXml.contains("""from="32"""") && morphoXml.contains("""to="34""""),
"Annotation should be on span 32-34 (ID 7), but morpho.xml content was:\n$morphoXml"
)
diff --git a/gradlew b/gradlew
index 1b6c787..f1c56bb 100755
--- a/gradlew
+++ b/gradlew
@@ -86,7 +86,7 @@
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m" "-XX:+IgnoreUnrecognizedVMOptions" "--enable-native-access=ALL-UNNAMED"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
diff --git a/gradlew.bat b/gradlew.bat
index 107acd3..bb10664 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -33,7 +33,7 @@
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" "-XX:+IgnoreUnrecognizedVMOptions" "--enable-native-access=ALL-UNNAMED"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome