Giter Site home page Giter Site logo

niklasberglund / swiftchinese Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 14.59 MB

Core Data framework for translating between Chinese and English with local CC-CEDICT Core Data store

License: MIT License

Swift 10.99% Objective-C 8.76% Ruby 0.31% C 71.06% C++ 5.96% Shell 2.93%
chinese translation language cc-cedict swift swift-3 dictionary dictionary-conversion

swiftchinese's Introduction

SwiftChinese

Swift 3 framework for translating between Chinese and English with CC-CEDICT using Core Data. CC-CEDICT is a CC-BY SA 3.0 licensed English - Chinese dictionary database. Read more about it at https://cc-cedict.org/wiki/.

What is CC-CEDICT?

From https://cc-cedict.org/wiki/:

CC-CEDICT is a continuation of the CEDICT project. The objective of the CEDICT project was to create an online, downloadable (as opposed to searchable-only) public-domain Chinese-English dictionary. CEDICT was started by Paul Andrew Denisowski in October 1997. For the most part, the project is modeled on Jim Breen's highly successful EDICT (Japanese-English dictionary) project and is intended to be a collaborative effort, with users providing entries and corrections to the main file.

Usage example

Searching translations

Translations are returned as Translation objects which holds the word in Chinese and it's English definitions.

Search by simplified Chinese

let dictionary = Dictionary()
let translations: [Translation] = dictionary.translationsFor(simplifiedChinese: "")

Search by English definition

let dictionary = Dictionary()
let translations: [Translation] = dictionary.translationsFor(english: "good")

Importing latest CC-CEDICT data

Error handling omitted for brevity. Remember to catch exceptions.

do {
    // Latest CC-CEDICT
    let exportInfo = try DictionaryExportInfo.latestDictionaryExportInfo()
    let export = DictionaryExport(exportInfo: exportInfo!)
    
    // Download the dictionary export
    export.download(onCompletion: { (exportContent, error) in
        guard error == nil else {
            debugPrint("Unable to download dictionary export. Aborting.")
            return
        }
        
        // Dictionary object used for getting translations
        let dictionary = Dictionary()
        debugPrint("Number of entries in dictionary before import: " + String(dictionary.numberOfEntries()))
        
        // Do an import
        let importer = Importer(dictionaryExport: export)
        importer.importTranslations(onProgress: { (totalEntries, progressedEntries) in
            // Progress update
            debugPrint("progressedEntries: \(progressedEntries), totalEntries: \(totalEntries)")
        }, whenFinished: { (error, newEntries, updatedEntries, removedEntries) in
            debugPrint("Number of entries in dictionary before import: " + String(dictionary.numberOfEntries()))
        })
    })
}
catch let error {
    debugPrint(error)
}

swiftchinese's People

Contributors

niklasberglund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ssorckcam

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.