fix-gloss
This commit is contained in:
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 114 KiB |
+9
-2
@@ -76,12 +76,19 @@ pub fn insert_word (
|
|||||||
entry : serde_json::Value,
|
entry : serde_json::Value,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
use crate::schema::words;
|
use crate::schema::words;
|
||||||
|
let word = entry_as_word (&entry)?;
|
||||||
let new_word = NewWord {
|
let new_word = NewWord {
|
||||||
word: entry_as_word (&entry)?,
|
word,
|
||||||
info: &entry.to_string (),
|
info: &entry.to_string (),
|
||||||
};
|
};
|
||||||
diesel::insert_into (words::table)
|
diesel::insert_into (words::table)
|
||||||
.values (new_word)
|
.values (new_word)
|
||||||
.execute (conn).ok ()?;
|
.execute (conn).map_or_else (
|
||||||
|
|e| {
|
||||||
|
println! ("error for {}: {}", word, e);
|
||||||
|
None
|
||||||
|
},
|
||||||
|
Some
|
||||||
|
)?;
|
||||||
Some (())
|
Some (())
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-4
@@ -2,6 +2,8 @@ pub mod models;
|
|||||||
pub mod schema;
|
pub mod schema;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
|
use diesel::SqliteConnection;
|
||||||
|
use diesel::r2d2::{ConnectionManager, Pool, PooledConnection};
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use indicatif::ParallelProgressIterator;
|
use indicatif::ParallelProgressIterator;
|
||||||
@@ -33,6 +35,18 @@ fn open_wiktextract_dump (path : PathBuf) -> Result<
|
|||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
const wiktextract_dump_lines : u64 = 10736399;
|
const wiktextract_dump_lines : u64 = 10736399;
|
||||||
|
|
||||||
|
fn do_line (
|
||||||
|
conn: &mut PooledConnection<ConnectionManager<SqliteConnection>>,
|
||||||
|
retries : &RwLock<Vec<String>>,
|
||||||
|
line : String
|
||||||
|
) {
|
||||||
|
if let Ok (word) = serde_json::from_str::<Value> (&line) {
|
||||||
|
if let None = db::insert_word (conn, word) {
|
||||||
|
retries.write ().unwrap ().push (line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), String> {
|
fn main() -> Result<(), String> {
|
||||||
let args = Args::parse ();
|
let args = Args::parse ();
|
||||||
let d = open_wiktextract_dump (args.wiktextract_dump).unwrap ();
|
let d = open_wiktextract_dump (args.wiktextract_dump).unwrap ();
|
||||||
@@ -46,15 +60,21 @@ fn main() -> Result<(), String> {
|
|||||||
.par_bridge ()
|
.par_bridge ()
|
||||||
.progress_with (bar);
|
.progress_with (bar);
|
||||||
let pool = db::get_pool ();
|
let pool = db::get_pool ();
|
||||||
|
let retries = RwLock::new (vec! []);
|
||||||
|
|
||||||
lines.for_each (|line| {
|
lines.for_each (|line| {
|
||||||
let conn = &mut pool.clone ().get ().unwrap ();
|
let conn = &mut pool.clone ().get ().unwrap ();
|
||||||
if let Ok (word) = serde_json::from_str::<Value> (
|
do_line (conn, &retries, line)
|
||||||
&line
|
});
|
||||||
) {
|
|
||||||
|
println! ("do retries now");
|
||||||
|
let conn = &mut pool.clone ().get ().unwrap ();
|
||||||
|
for line in retries.read ().unwrap ().iter () {
|
||||||
|
println! ("retrying");
|
||||||
|
if let Ok (word) = serde_json::from_str::<Value> (&line) {
|
||||||
db::insert_word (conn, word);
|
db::insert_word (conn, word);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,19 @@
|
|||||||
(when-some [[_ word gloss] (re-matches #"([^\t]*)\t(.*)\n?" s)]
|
(when-some [[_ word gloss] (re-matches #"([^\t]*)\t(.*)\n?" s)]
|
||||||
[word gloss]))
|
[word gloss]))
|
||||||
|
|
||||||
(defn lookup-word [word]
|
(defn query-word [word]
|
||||||
(let [ds (sql/get-datasource {:dbtype "sqlite" :dbname "db/words.db"})]
|
(let [ds (sql/get-datasource {:dbtype "sqlite" :dbname "db/words.db"})]
|
||||||
(with-open [conn (sql/get-connection ds)]
|
(with-open [conn (sql/get-connection ds)]
|
||||||
(->> (sql/execute! conn ["select info from words where word = ?"
|
(->> (sql/execute! conn ["select info from words where word = ?"
|
||||||
word])
|
word])
|
||||||
(map #(json/parse-string (:words/info %) keyword))
|
(map #(json/parse-string (:words/info %) keyword))))))
|
||||||
(mapcat :senses)
|
|
||||||
(mapcat :raw_glosses)
|
(defn gloss-word [word]
|
||||||
first))))
|
(->> word
|
||||||
|
query-word
|
||||||
|
(mapcat :senses)
|
||||||
|
(mapcat (some-fn :raw_glosses :glosses))
|
||||||
|
first))
|
||||||
|
|
||||||
(defn parse-chat-message [x]
|
(defn parse-chat-message [x]
|
||||||
(when-let [[_ _dead? author body]
|
(when-let [[_ _dead? author body]
|
||||||
@@ -52,7 +56,7 @@
|
|||||||
(defn do-definition [s]
|
(defn do-definition [s]
|
||||||
(when-some [w (find-word s)]
|
(when-some [w (find-word s)]
|
||||||
(l/infof "looking up word: %s" w)
|
(l/infof "looking up word: %s" w)
|
||||||
(let [r (lookup-word w)]
|
(let [r (gloss-word w)]
|
||||||
(if r
|
(if r
|
||||||
(l/infof "found word! %s" r)
|
(l/infof "found word! %s" r)
|
||||||
(l/infof "no entry... %s" w))
|
(l/infof "no entry... %s" w))
|
||||||
|
|||||||
Reference in New Issue
Block a user