Giter VIP home page Giter VIP logo

jm_dict's Introduction

jm_dict

Pub

Implementation of the JMdict Japanese Dictionary Project as a Flutter plugin.

Usage of this plugin must conform to the Attribution and Credits section below.

Getting Started

This plugin enables your app to load and use the Japanese Dictionary provided by JMdict/EDICT Project. Supports looking up entries by kana, romaji, kanji and the meaning/glossary content. Currently doesn't support entry editing.

This plugin stores the dictionary locally and uses ObjectBox as it's local database architecture. There are three ways to initiate the plugin and it requires the file JMdict.gz, which contains the JMdict XML file.

Provide from Asset

Place the JMdict.gz file within your project, typically on the same level as the lib folder/inside a folder on the same level as the lib folder, then include it on the project's pubspec.yaml.

# For example, the file is placed inside assets folder,
# which is located on the same level with the lib folder
assets:
    - assets/JMdict.gz

Then call the initFromAsset method

import 'package:jm_dict/jm_dict.dart';

JMDict().initFromAsset(assetPath: "assets/JMdict.gz",);

Why init from the gz file? The real XML file has the size of ±100MBs, which is too large to be included locally as an asset

Provide from File

Let's say you obtained the content of JMdict.gz, which is the JMdict XML file somewhere, you can call the initFromFile method.

import 'package:jm_dict/jm_dict.dart';
import 'package:path_provider/path_provider.dart' as PathProvider;

final tempDir = await PathProvider.getTemporaryDirectory();
final File jmDictXmlFile = File("${tempDir.uri.getFilePath()}JMdict",);

JMDict().initFromFile(xmlFile: jmDictXmlFile,);

Provide Online

You can provide the JMdict.gz file by downloading it. This plugin can download it from a default URL, or you can provide an alternative download URL.

import 'package:jm_dict/jm_dict.dart';

JMDict().initFromNetwork();

/// with alternative download URL
JMDict().initFromNetwork(
  archiveUri: Uri.parse(
    "https://mystorage.somewhere.com/download/JMdict.gz",
  ),
);

Note: this will take a while, since it will download a file with a size of ±20 MBs, on a slower connection, might take minutes.

Searching Entries

Basic Search Usage

Look for results by providing a single keyword.

import 'package:jm_dict/jm_dict.dart';

final dict = JMDict();

/// Returns result that has romaji readings of "kensaku", or if the glossary/meaning
/// contains the word "kensaku"
dict.search(
  keyword: "kensaku",
)

/// Should return the same result as the above one, but might return less results since
/// glossaries usually don't contain kana
dict.search(
  keyword: "けんさく",
);

/// This will return more specific results, looking for entries that contain this
/// kanji keyword
dict.search(
  keyword: "検索",
);

Limiting Results/Pagination

You can provide additional argument to limit the search result count, and how many results to skip.

import 'package:jm_dict/jm_dict.dart';

final dict = JMDict();

/// Limit search results to 10
dict.search(
  keyword: "sakai", limit: 10,
);

/// Skip first 10 results
dict.search(
  keyword: "sakai", offset: 10,
);

/// Limit search results to 10, skips the first 20 results
dict.search(
  keyword: "saka", limit: 10, offset: 20,
);

Limitations

There are some use cases to consider when searching:

  • Searching using mixed keywords won't work, e.g "hige男", "kamisatoけ". This will be considered in future versions
  • Each entry in the dictionary has more accessible traits, which is available on search results, e.g: dialects, word category, etc. For this release, the query process will only look for keywords in kana, romaji, and kanji texts only and further filters can be created manually, e.g using List.where. This will be considered in future releases as well.
  • Sorting isn't available for now. You can use List.sort for now and specify your own sorting preferences.
  • There's a consideration of writing certain entries into the local database, to reduce the DB size. For now this plugin writes the whole file.

Attribution and Credits

CC BY-SA 3.0

This package uses the JMdict/EDICT dictionary file. This file is the property of the Electronic Dictionary Research and Development Group, and is used in conformance with the Group's licence which are made available under Creative Commons Attribution-ShareAlike 3.0 Unported.

jm_dict's People

Contributors

nsneruno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.