Skip to content

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

License

Notifications You must be signed in to change notification settings

Cinher/mdict-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MDict Library in pure java !

It supports:
   I.lzo(via lzo-core-1.0.5.jar)
  II.Ripemd128 key-info encryption.
 III.Mdx add Mdd Builders.

and is able to do:
   I.Basic query.
  II.Conjuction search.
 III.Fast Fuzzy search (with wild cards).
 IV.Fast Fulltext retrieval (with wild cards).

App Released!

Get it on Google Play
image

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!=-1){
  String html_contents = md.getRecordAt(search_result);
  String entry_name = md.getEntryAt(search_result);
}

2.Search in a bunch of dicts:

String key = "happy";
ArrayList<mdict> mdxs = new ArrayList<mdict>();
mdxs.add(path1);
mdxs.add(path2);
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____@398825@0@16905@1@16906@1】...【other results】...
how to handle:
String 
html_contents0 = mdxs.get(0).getRecordAt(398825),
html_contents1 = mdxs.get(1).getRecordAt(16905),
html_contents2 = mdxs.get(1).getRecordAt(16906);
...  
...
*/

details

  • This project was initially converted from xiaoqiangWang's python analyzer.
  • Use red-black tree and binary-list-searching(mainly) to implement dict funcitons.
  • Feng Dihai(@fengdh)'s mdict-js is of help too, I've just switched to use the same elegant binary-list-searching method——reduce().Somehow, this function always returns the first occurence of the entry >= keyword, maybe some mathematician could tell me why, but I've tested over 100000 times without any expectation.
/*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;
	}
}

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%