Coder Social home page Coder Social logo

knifer / mdict-java Goto Github PK

View Code? Open in Web Editor NEW
159.0 10.0 51.0 29.25 MB

Query library for Mdict (mdx or mdd) , a popular dictionary file format.

License: GNU General Public License v3.0

Java 93.84% CSS 0.17% JavaScript 2.14% HTML 3.83% Batchfile 0.01% Shell 0.01% VBScript 0.01%
dictionary mdx mdd mdict-reader mdict-android mdxbuilder

mdict-java's Introduction

MDict Library in pure java !

image

It supports:
   I.Lzo compressed contents. (via lzo-core)
  II.Ripemd128 key-info decryption.
 III.Builders to make Mdx add Mdd.

and is able to do:
   I.Basic query.
  II.Conjuction search.
 III.Fast wildcard match among entries.
 IV.Fast Fulltext retrieval. (also with wild cards)

Android App

https://github.com/KnIfER/PlainDictionaryAPP

Usage:

1.Basic query:

String key = "happy";
mdict md = new mdict(path);
int search_result = md.lookUp(key, true);//true means to match strictly  
if(search_result>=0){
  String html_contents = md.getRecordAt(search_result);
  String entry_name = md.getEntryAt(search_result);
}

2.Search in a bunch of dicts:

key = "happy";
ArrayList<mdict> mdxs = new ArrayList<>();
...
RBTree_additive combining_search_tree = new RBTree_additive();
for(int i=0;i<mdxs.size();i++)
{
  mdxs.get(i).size_confined_lookUp(key,combining_search_tree,i,30);
}  	
combining_search_tree.inOrder();//print results stored in the RBTree

/*printed results looks like 【happy____@111@0@222@1@16906@1】...【other results】...
how to handle:
String html_contents0 = mdxs.get(0).getRecordAt(111);
...
...  
...
*/

details

  • This project was initially converted from xiaoqiangWang's python analyzer.
  • Use red-black tree and binary-list-searching(mainly) to implement dictionary funcitons.
  • Feng Dihai(@fengdh)'s mdict-js is of help too, I've just switched to use the same short but elegant binary-list-searching method——reduce().Somehow, this function always returns the first occurence of the entry >= keyword, in a pre-sorted list that contain entries. maybe some mathematician could tell me why, but I've tested over 100000 times without any expectation.
  • Maybe I should oneday replace red-black tree and the recursive reduce method with Arrays.binarySearch, but I am lazy...
/*via mdict-js
 *note at first time we feed in 0 as start and array.length as end. it must not be array.length-1. 
*/
public static int reduce(int phrase, int[] array,int start,int end) {
	int len = end-start;
	if (len > 1) {
	  len = len >> 1;
	  return phrase > array[start + len - 1]
				? reduce(phrase,array,start+len,end)
				: reduce(phrase,array,start,start+len);
	} else {
	  return start;
	}
}

MDX File Format

MDD File Format

Source Code License: Apache2.0 for the core part, specifically anything under the package of com.knziha.plod.dictionary.*; GPL3.0 for everything else including the mdictBuilder, UI part, and the android application. As for the License of mdx file format itself, well, you know, mdict is an open dictionary platform.

mdict-java's People

Contributors

knifer avatar knilight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdict-java's Issues

java1.8报错

../com/knziha/plod/dictionary/mdict.java:374: 错误: 找不到符号
int blockId = accumulation_blockId_tree.xxing(new myCpr(position,1)).getKey().value;
^
符号: 变量 value
位置: 接口 Comparable
../com/knziha/plod/dictionary/mdict.java:383: 错误: 找不到符号
int Rinfo_id = accumulation_RecordB_tree.xxing(new myCpr(infoI.key_offsets[i],1)).getKey().value;
^
符号: 变量 value
位置: 接口 Comparable
../com/knziha/plod/dictionary/mdict.java:941: 错误: 找不到符号
int RecB_ID = accumulation_RecordB_tree.xxing(new myCpr(infoI.key_offsets[position],1)).getKey().value;
^
符号: 变量 value
位置: 接口 Comparable
../com/knziha/plod/dictionary/mdict.java:1172: 错误: 找不到符号
int blockId = accumulation_blockId_tree.xxing(new myCpr(position,1)).getKey().value;
^
符号: 变量 value
位置: 接口 Comparable
注: ../com/knziha/plod/dictionary/mdict.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
4 个错误
我在MAC下尝试运行报错,这个怎么解决?

Can't get content.

I do my best to look at your code and have some problems getting the contents of the entries.
Is there an easy way to get entry's contents?
For example, the method passed in entry returns the content collection.

mdict source:

abchasicus -a -um, abschasicus -a -um
<h2>abchasicus -a -um, abschasicus -a -um</h2> from Abkhasia in the Caucasus

</>

java code ( Example2.java ):

    public static void main(String[] args) throws IOException {
        String mdxPath = new Example2().getClass().getClassLoader().getResource("assets/NameOfPlants.mdx").getPath();
        System.out.println("mdxPath: " + mdxPath);

        mdict mdx = new mdict(mdxPath);
        String key = "abchasicus -a -um, abschasicus -a -um";
        int lookUp = mdx.lookUp(key);
        System.out.println(mdx.getRecordAt(lookUp));
    }

output:

mdxPath: ***/assets/NameOfPlants.mdx
key_block_info_size =228

开始打印头部信息 Red-Black 树...
a, ab_0
carduacus -a -um_1
elatus -a -um_2
incognitus -a -um_3
nesioticus -a -um_4
revirescens_5
triqueter, triquetrus -a -um_6

accumulation_blockId_tree_TIME 建树时间=1
block_blockId_search_tree_TIME 建树时间=0
17457
17457
0blockId
�

How to build

Thanks for this great project! But it seems not intuitive to build this app. Can you shed some lights on that?

can't compile in Android

i put the files into a android project,

android studio compaint like that:

int blockId = accumulation_blockId_tree.xxing(new myCpr(position,1)).getKey().value;

getKey().value can not found def

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.