コード例 #1
0
# coding=utf-8
# Machine Learning language identification (document classification) program
# Implements a bag of words model with Naive Bayes Classifier
# Designed for use with languages which use the Latin alphabet.

import sys
import codecs
import math

import langlib

SMOOTHING_PARAM = 1 # Smoothing parameter for Laplace smoothing

 # Dictionary of language objects
languages = {}
langlib.loadLanguages(languages)

def train():
    """ Training mode. Assumes all training exercises have never been seen before. """
    
    for lang in languages.iterkeys():
        # Read in documents so that UTF-8 encoding is handled properly
        f = codecs.open('trainingTexts/' + languages[lang].fileName, encoding='utf-8')
        texts = f.read().split('====') # Individual documents are separated by ====
        f.close()
        
        for text in texts:
            processed = langlib.processText(text)
            
            # Convert processed into a Document representing a bag of words
            document = langlib.Document()
コード例 #2
0
ファイル: es.py プロジェクト: ThaPwned/EventScripts-Emulator
    try:
      for j in script.info.keylist:
        dbgmsg(0, "[EventScripts]    %8s: %s" % (j, script.info[j]))
    except AttributeError:
      pass

_gamename = str(ServerVar('eventscripts_gamedir')).rsplit(os.sep, 1)[~0]
def getGameName():
   return _gamename

def getAddonPath(addon):
    return "%s/%s" % (ServerVar("eventscripts_addondir"), addon)

def local_language():
    ''' Returns the server's local language abbreviation
    '''
    return langlib.getLangAbbreviation(str(ServerVar("eventscripts_language")))

# initialize the language libraries
langlib.loadLanguages("%s/_libs/python/deflangs.ini" % ServerVar("eventscripts_addondir"))
langlib.setDefaultLangCallback(local_language)

############################################
# Backwards compatibility patching section
############################################
#replace menu definitions since showMenu works better from Python than es.menu()
_esshell_menu = menu
menu = showMenu

dbgmsg(1,"[EventScripts] es.py loaded.")
コード例 #3
0
ファイル: es.py プロジェクト: fizek/source_addons
_gamename = str(ServerVar('eventscripts_gamedir')).rsplit(os.sep, 1)[~0]


def getGameName():
    return _gamename


def getAddonPath(addon):
    return "%s/%s" % (ServerVar("eventscripts_addondir"), addon)


def local_language():
    ''' Returns the server's local language abbreviation
    '''
    return langlib.getLangAbbreviation(str(ServerVar("eventscripts_language")))


# initialize the language libraries
langlib.loadLanguages("%s/_libs/python/deflangs.ini" %
                      ServerVar("eventscripts_addondir"))
langlib.setDefaultLangCallback(local_language)

############################################
# Backwards compatibility patching section
############################################
#replace menu definitions since showMenu works better from Python than es.menu()
_esshell_menu = menu
menu = showMenu

dbgmsg(1, "[EventScripts] es.py loaded.")