Skip to content
Open
Show file tree
Hide file tree
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
Binary file modified db/cc-cedict.sqlite
Binary file not shown.
Binary file added db/cc-cedict_old.sqlite
Binary file not shown.
52 changes: 34 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path');
var Sequelize = require('sequelize');
var sequelize = new Sequelize(null, null, null, {
dialect: 'sqlite',
storage: path.join(__dirname, './db/cc-cedict.sqlite')
storage: path.join(__dirname, './db/cc-cedict.sqlite'),
logging: false
});

var Word = sequelize.define('Word', {
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports.searchByChinese = function(str, cb){
var results = [];
_.each(words, function(word){
var pronunciation = word.pronunciation;
var prettified = pinyin.prettify(pronunciation.slice(1, pronunciation.length - 1));
var prettified = pinyin.prettify(pronunciation.slice(1, pronunciation.length - 1).replace(/u\:/g, "v"));
results.push({
traditional: word.traditional,
simplified: word.simplified,
Expand All @@ -62,10 +63,25 @@ module.exports.searchByPinyin = function(str, cb) {
_.each(parts, function(part) {
var numeric = part.replace(/\D/g,'');

// Convert ü/v to u: as used in dictionary
var newPart = [];
var umlat = false;
_.each(part.split(""), function(char) {
if (char === "ü" || char === "v") {
newPart.push("u");
newPart.push(":");
umlat = true;
} else {
newPart.push(char);
}
});
if (umlat)
newStr.push(newPart.join(""));

if (numeric === "") {
part += "5";
newStr.push(part);
} else {
} else if (!umlat) {
newStr.push(part);
}
});
Expand All @@ -77,21 +93,21 @@ module.exports.searchByPinyin = function(str, cb) {
};

Word
.findAll(query)
.then(function(words) {
var results = [];
_.each(words, function(word) {
var pronunciation = word.pronunciation;
var prettified = pinyin.prettify(pronunciation.slice(1, pronunciation.length - 1));
results.push({
traditional: word.traditional,
simplified: word.simplified,
pronunciation: prettified,
definitions: word.definitions
});
});
cb(results);
.findAll(query)
.then(function(words) {
var results = [];

_.each(words, function(word) {
var pronunciation = word.pronunciation;
var prettified = pinyin.prettify(pronunciation.slice(1, pronunciation.length - 1).replace(/u\:/g, "v"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the whitespace here

results.push({
traditional: word.traditional,
simplified: word.simplified,
pronunciation: prettified,
definitions: word.definitions
});
});
cb(results);
});
}

Expand Down
5 changes: 3 additions & 2 deletions parser/dictionary-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var fs = require('fs');
// defined db config
var sequelize = new Sequelize(null, null, null, {
dialect: 'sqlite',
storage: '../db/cc-cedict.sqlite'
storage: '../db/cc-cedict.sqlite',
logging: false
});

// create a sqlite database with every entry
Expand Down Expand Up @@ -48,7 +49,7 @@ fs.readFile('../src/cc-cedict.txt', 'UTF-8', function(err, data){
var simplified = spaceSplit[1];

var regex = /\[(.*?)\]/;
var pronunciation = line.match(regex)[0];
var pronunciation = line.match(regex)[0].toLowerCase();

var slashSplit = line.split('/');
var defs = slashSplit.slice(1, slashSplit.length - 1).join('; ');
Expand Down
Loading