Permalink
Browse files

Fix author -> authors alias, load managed

  • Loading branch information...
1 parent 45141c0 commit db45b822f5c4a74009557cb4ba31ef653c6241c3 @colder committed Aug 28, 2012
@@ -260,10 +260,11 @@ object BibTeXEntry {
var seqFields = Map[String, Seq[MString]]()
for ((field, value) <- map) {
- if (!isSeqField(field)) {
- fields += field -> value
+ val f = if (field == "author") "authors" else field
+ if (!isSeqField(f)) {
+ fields += f -> value
} else {
- seqFields += field -> value.toJava.split(" and ").map(MString.fromJava _).toSeq
+ seqFields += f -> value.toJava.split(" and ").map(MString.fromJava _).toSeq
}
}
@@ -4,6 +4,9 @@ package modules
import akka.actor._
import data._
import strings._
+import bibtex._
+
+import scala.io.Source
class Managed(val repl: ActorRef, val console: ActorRef, val settings: Settings) extends Module
with LuceneRAMBackend
@@ -12,13 +15,18 @@ class Managed(val repl: ActorRef, val console: ActorRef, val settings: Settings)
val source = "managed"
- override def preStart = {
- super.preStart
-
- // Load managed.bib into lucene
- }
+ val managedPath = settings("general", "bib.filename")
override def receive: Receive = {
+ case msg @ OnStartup(os) =>
+ super[Module].receive(msg)
+
+ val parser = new BibTeXParser(Source.fromFile(managedPath), console ! Error(_))
+
+ for (entry <- parser.entries) {
+ addEntry(entry, None)
+ }
+
case Search(terms) =>
sender ! search(terms)
@@ -37,17 +45,14 @@ class Managed(val repl: ActorRef, val console: ActorRef, val settings: Settings)
onImport(res)
// no message back
- case _: Command =>
- sender ! CommandUnknown
-
- case _ =>
+ case msg =>
+ super[Module].receive(msg)
}
private def doImport(res: SearchResult) {
import java.io.{FileWriter,File}
- val fn = settings("general", "bib.filename")
- val fw = new FileWriter(new File(fn), true)
+ val fw = new FileWriter(new File(managedPath), true)
fw.write(res.entry.toString)
fw.write("\n\n")
fw.close
@@ -81,15 +81,12 @@ class ResultStore(val repl: ActorRef, val console: ActorRef, val settings: Setti
private def displayResults() {
var i = 0
for (res <- results) {
- val spc = if (i < 10) "" else " "
+ val spc = if (i < 10) " " else ""
- val colSourceCache = if (res.sources.contains("cache")) Console.YELLOW+"c"+Console.RESET else " "
- val colSourceDBLP = if (res.sources.contains("dblp")) Console.YELLOW+"w"+Console.RESET else " "
- val colSourceImported = if (res.sources.contains("managed")) Console.GREEN+"I"+Console.RESET else " "
- val colSourceLoad = if (res.sources.contains("loaded")) Console.GREEN+"L"+Console.RESET else " "
- val colInvalid = if (!res.entry.isValid) Console.RED+"!"+Console.RESET else " "
+ val colSourceImported = if (res.sources.contains("managed")) Console.GREEN+Console.BOLD+"m"+Console.RESET else " "
+ val colInvalid = if (!res.entry.isValid) Console.RED+Console.BOLD+"!"+Console.RESET else " "
- val extraCols = colSourceCache+colSourceDBLP+colSourceImported+colSourceLoad+colInvalid
+ val extraCols = colSourceImported+colInvalid
console ! Info("["+i+spc+" "+extraCols+"] "+res.entry.inlineString)
i += 1

0 comments on commit db45b82

Please sign in to comment.