Skip to content

Commit 4adff86

Browse files
committed
Added langCode, withoutFormatExt, TeiMetadata, distinguish PID and title
1 parent 59ebad0 commit 4adff86

38 files changed

Lines changed: 845 additions & 126 deletions

server/src/main/kotlin/org/ivdnt/galahad/annotations/Layer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const val SOURCE_LAYER_NAME: String = "sourceLayer"
1010
class Layer(
1111
/** Documents in this layer. (Formats like conllu support multiple documents.) */
1212
val documents: Array<DocumentLayer>,
13-
/** ID of this layer. Ideally the file PID as documents may have different ids. */
13+
/** ID of this layer. Ideally this is the file PID, so that documents may have different ids. */
1414
val id: String = UUID.randomUUID().toString(),
1515
) {
1616
/** Terms in this layer. Documents, paragraphs, sentences flattened. */

server/src/main/kotlin/org/ivdnt/galahad/corpora/MutableCorpusMetadata.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ open class MutableCorpusMetadata(
3333
@JsonIgnore
3434
var user: User? = null
3535

36+
@get:JsonIgnore
37+
val langCode: String
38+
// iso 639 code. "und" for undefined.
39+
get() = Locale.getAvailableLocales().find { it.getDisplayLanguage(Locale.ENGLISH).equals(language, true) }?.isO3Language ?: "und"
40+
3641
/**
3742
* Whether the user is in the list of collaborators of this corpus.
3843
* Note that this is not the same as having write access: use [hasWriteAccess].

server/src/main/kotlin/org/ivdnt/galahad/documents/DocumentFormat.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ enum class DocumentFormat(val identifier: String, val extension: String) {
2626
override fun toString(): String = identifier
2727

2828
companion object {
29+
val extensions: Set<String>
30+
get() = entries.map { "." + it.extension }.toSet()
31+
2932
// Used by Spring.
3033
@JsonCreator
3134
fun fromString(s: String): DocumentFormat =

server/src/main/kotlin/org/ivdnt/galahad/export/CmdiMetadata.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.ivdnt.galahad.util.XmlUtil
77
import org.ivdnt.galahad.util.child
88
import org.ivdnt.galahad.util.childElements
99
import org.ivdnt.galahad.util.ifNullOrBlank
10+
import org.ivdnt.galahad.util.withoutFormatExt
1011
import org.w3c.dom.Element
1112
import org.w3c.dom.Node
1213
import java.io.OutputStream
@@ -22,7 +23,7 @@ import javax.xml.transform.stream.StreamResult
2223
* the metadata values in the DOM with each instance.
2324
*/
2425
class CmdiMetadata(val export: DocumentExport) {
25-
private val docTitle = export.document.uploadedFile.nameWithoutExtension
26+
private val docTitle = export.document.uploadedFile.withoutFormatExt
2627
private val corpus: MutableCorpusMetadata = export.corpus.mutableMetadata
2728
private val format = export.format.identifier
2829
private val now = Date()

server/src/main/kotlin/org/ivdnt/galahad/formats/naf/NafWriter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.ivdnt.galahad.annotations.Annotation
44
import org.ivdnt.galahad.export.DocumentExport
55
import org.ivdnt.galahad.export.LayerWriter
66
import org.ivdnt.galahad.util.XmlUtil
7+
import org.ivdnt.galahad.util.withoutFormatExt
78
import org.w3c.dom.Document
89
import org.w3c.dom.Element
910
import java.io.OutputStream
@@ -17,7 +18,7 @@ class NafWriter(export: DocumentExport) : LayerWriter(export) {
1718
val xml = XmlUtil.builder.newDocument()
1819
val root = xml.createElement("NAF").apply {
1920
setAttribute("version", "v3.3")
20-
setAttribute("xml:lang", "dum")
21+
setAttribute("xml:lang", export.corpus.mutableMetadata.langCode)
2122
}
2223
xml.appendChild(root)
2324

@@ -40,7 +41,7 @@ class NafWriter(export: DocumentExport) : LayerWriter(export) {
4041
root.appendChild(nafHeader)
4142

4243
val fileDesc = xml.createElement("fileDesc").apply {
43-
setAttribute("title", export.document.name)
44+
setAttribute("title", export.document.uploadedFile.withoutFormatExt)
4445
setAttribute("author", export.user.id)
4546
setAttribute("creationtime", now.toString())
4647
setAttribute("filename", export.document.name)

server/src/main/kotlin/org/ivdnt/galahad/formats/tei/TeiMetadata.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.ivdnt.galahad.export.DocumentExport
66
import org.ivdnt.galahad.util.XmlUtil
77
import org.ivdnt.galahad.util.childOrNull
88
import org.ivdnt.galahad.util.ifNullOrBlank
9+
import org.ivdnt.galahad.util.withoutFormatExt
910
import org.w3c.dom.Document
1011
import org.w3c.dom.Element
1112
import org.w3c.dom.Node
@@ -32,7 +33,7 @@ class TeiMetadata(
3233
?.childOrNull("titleStmt")
3334
?.childOrNull("title")?.textContent
3435
?: // if null, use filename without extension
35-
export.document.uploadedFile.nameWithoutExtension
36+
export.document.uploadedFile.withoutFormatExt
3637
}
3738

3839
private val corpusMetadata: MutableCorpusMetadata = export.corpus.mutableMetadata

0 commit comments

Comments
 (0)