Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class BibtexConverterService(private val studyReviewIdGeneratorService: IdGenera
}

private fun convertMany(bibtex: String): Pair<List<Study>, List<String>> {
val cleanedBibtex = removeBibtexComments(bibtex)

val validStudies = mutableListOf<Study>()
val invalidEntries = mutableListOf<String>()

bibtex.split(Regex("(?=\\s*@)"))
cleanedBibtex.split(Regex("(?m)(?=@\\w+\\s*\\{)"))
.map { it.trim() }
.filter { it.isNotBlank() }
.forEach { entry ->
Expand Down Expand Up @@ -111,6 +113,20 @@ class BibtexConverterService(private val studyReviewIdGeneratorService: IdGenera
return Study(type, title, year, authors, venue, abstract, keywords, references, doi)
}

private fun removeBibtexComments(bibtex: String): String {
return bibtex.lines()
.mapNotNull { line ->
if (line.trimStart().startsWith("%")) {
null
} else {
val commentIndex = line.indexOf('%')
val cleaned = if (commentIndex >= 0) line.take(commentIndex) else line
cleaned.trimEnd().takeIf { it.isNotBlank() }
}
}
.joinToString("\n")
}

private fun parseBibtexFields(bibtexEntry: String): Map<String, String> {
val content = bibtexEntry.substringAfter('{', "").substringBeforeLast('}', "")
if (content.isBlank()) {
Expand Down
Loading