Last active
August 27, 2021 12:46
-
-
Save beatrizsanchez/117ce9c35dc6a913e236c07c571a9546 to your computer and use it in GitHub Desktop.
Bibliography (BibTeX) Validator with EVL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pre { | |
"starting validation".println(); | |
for (m in Misc.all().sortBy(e|e.year).collect(e|e.id + ": " + e.month + ", " + e.year)){ | |
m.println("Misc: "); | |
} | |
for (a in Article.all.journal.asSet().sortBy(a|a)){ | |
a.println("Journal: "); | |
} | |
"START OF CONSTRAINTS".println(); | |
} | |
//book ( author or editor, title, publisher, year.) | |
context Book { | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "book title is undefined for " + self.id | |
} | |
constraint HasAuthors { | |
check: self.author.isDefined() | |
message: "book authors undefined for " + self.id | |
} | |
constraint HasISBN { | |
check: self.isbn.isDefined() | |
message: "book ISBN undefined for " + self.id | |
} | |
constraint NoEditors { | |
check: not self.editor.isDefined() | |
message: "editor should not be defined for " + self.id | |
fix { | |
title : "Remove editor" | |
do { | |
self.editor = ""; | |
} | |
} | |
} | |
} | |
//phdthesis (author, title, school, year) | |
context Phdthesis { | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "thesis title is undefined for " + self.id | |
} | |
constraint HasAuthors { | |
check: self.author.isDefined() | |
message: "thesis author is undefined for " + self.id | |
} | |
constraint HasSchool { | |
check: self.school.isDefined() | |
message: "thesis school is undefined for " + self.id | |
} | |
constraint HasYear { | |
check: self.year.isDefined() | |
message: "thesis year is undefined for " + self.id | |
} | |
} | |
//article (author, title, journal, year) | |
// An article from a Journal | |
context Article { | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "article title is undefined for " + self.id | |
} | |
constraint HasAuthors { | |
check: self.author.isDefined() | |
message: "article authors is undefined for " + self.id | |
} | |
constraint HasDOI { | |
check: self.doi.isDefined() | |
message: "article doi is undefined for " + self.id | |
} | |
constraint NoEditors { | |
check: not self.editor.isDefined() | |
message: "editor should not be defined for " + self.id | |
fix { | |
title : "Remove editor" | |
do { | |
self.editor = ""; | |
} | |
} | |
} | |
} | |
//An article in a conference proceedings. | |
// inproceedings (author, title, booktitle, year.) | |
context Inproceedings { | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "Inproceedings title is undefined for " + self.id | |
} | |
constraint HasAuthors { | |
check: self.author.isDefined() | |
message: "Inproceedings authors is undefined for " + self.id | |
} | |
constraint HasBookTitle { | |
check: self.booktitle.isDefined() | |
message: "Inproceedings booktitle is undefined for " + self.id | |
} | |
constraint BooktitleFormat { | |
guard: self.satisfies("HasBookTitle") and self.satisfies("HasTitle") and self.satisfies("HasAuthors") and self.satisfies("HasDoiOrUrl") | |
check: self.booktitle.startsWith("Proceedings") | |
message: "Inproceedings booktitle not well formatted for "+self.id+": " + self.booktitle | |
fix { | |
title : "Add 'Proceedings of '" | |
do { | |
self.booktitle = "Proceedings of " + self.booktitle; | |
} | |
} | |
fix { | |
title : "Add 'Proceedings '" | |
do { | |
self.booktitle = "Proceedings " + self.booktitle; | |
} | |
} | |
fix { | |
title : "Add 'Proceedings of the'" | |
do { | |
self.booktitle = "Proceedings of the " + self.booktitle; | |
} | |
} | |
} | |
constraint HasDoiOrUrl { | |
check: self.doi.isDefined() or self.url.isDefined() | |
message: "Inproceedings doi or url is undefined for " + self.id | |
} | |
constraint NoEditors { | |
check: not self.editor.isDefined() | |
message: "editor should not be defined for " + self.id | |
fix { | |
title : "Remove editor" | |
do { | |
self.editor = null; | |
} | |
} | |
} | |
} | |
// A part of a book having its own title. | |
// incollection (author, title, booktitle, publisher, year) | |
context Incollection{ | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "incollection title is undefined for " + self.id | |
} | |
constraint HasAuthors { | |
check: self.author.isDefined() | |
message: "incollection author is undefined for " + self.id | |
} | |
constraint HasDOI { | |
check: self.doi.isDefined() | |
message: "incollection doi is undefined for " + self.id | |
} | |
constraint HasBookTitle { | |
check: self.booktitle.isDefined() | |
message: "incollection booktitle is undefined for " + self.id | |
} | |
constraint NoEditors { | |
check: not self.editor.isDefined() | |
message: "editor should not be defined for " + self.id | |
fix { | |
title : "Remove editor" | |
do { | |
self.editor = ""; | |
} | |
} | |
} | |
} | |
//misc (optional fields: author, title, howpublished, month, year, note) | |
context Misc { | |
guard: self.id <> "DOORS" | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "misc title is undefined for " + self.id | |
} | |
constraint HasUrl { | |
check: self.url.isDefined() | |
message: "misc url is undefined for " + self.id | |
} | |
constraint UrlIsAccessible { | |
guard: self.satisfies("HasUrl") | |
check: self.url.getCode() == 200 | |
message: "url is not accessible for " + self.id + " return code was " + self.url.getCode() | |
} | |
constraint HasAccessDate { | |
guard: self.satisfies("HasUrl") and self.satisfies("UrlIsAccessible") | |
check: self.note.isDefined() and self.note.startsWith("[Accessed ") | |
message: "misc note with access date is undefined for " + self.id | |
fix { | |
title: "Update date" | |
do { | |
self.urldate = today(); | |
self.note = "[Accessed on "+today()+"]"; | |
} | |
} | |
} | |
constraint HasHowPublished { | |
check: self.howpublished.isDefined() and self.howpublished == "[Online]" | |
message: "howpublished is undefined for " + self.id | |
} | |
constraint HasYear { | |
check: self.year.isDefined() | |
message: "publish year is undefined for " + self.id | |
} | |
constraint HasMonth { | |
check: self.month.isDefined() | |
message: "publish month is undefined for " + self.id | |
} | |
constraint HasAuthor { | |
check: self.author.isDefined() | |
message: "author is undefined for " + self.id | |
} | |
} | |
//techreport (author, title, institution, year) | |
context Techreport{ | |
constraint HasTitle { | |
check: self.`title`.isDefined() | |
message: "techreport title is undefined for " + self.id | |
} | |
constraint HasInstitution { | |
check: self.institution.isDefined() | |
message: "techreport institution is undefined for " + self.id | |
} | |
constraint HasYear { | |
check: self.year.isDefined() | |
message: "techreport year is undefined for " + self.id | |
} | |
} | |
operation String getCode() : Integer { | |
var url = new Native("java.net.URL")(self.println("Attempting:")); | |
var huc = url.openConnection(); | |
var responseCode : Integer = huc.getResponseCode(); | |
return responseCode.println("response: "); | |
} | |
operation today() : String { | |
var df = new Native("java.text.SimpleDateFormat")("yyyy-MM-dd"); | |
return df.format(new Native("java.util.Date")); | |
//return "2021-06-22"; | |
} | |
post { | |
"finished validation".println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment