Exemplo n.º 1
0
	def callHandlerMethod(self, xWindow, eventObject, methodName):
		if methodName != "external_event":
			return False
		if eventObject == "ok":
			self.__saveOptionsFromWindowToRegistry(xWindow)
			PropertyManager.getInstance().reloadVoikkoSettings()
			return True
		if eventObject == "back" or eventObject == "initialize":
			self.__initOptionsWindowFromRegistry(xWindow)
			return True
		return False
Exemplo n.º 2
0
	def isValid(self, word, locale, properties):
		VoikkoHandlePool.mutex.acquire()
		try:
			voikko = VoikkoHandlePool.getInstance().getHandle(locale)
			if voikko is None:
				return False
			PropertyManager.getInstance().setValues(properties)
			result = voikko.spell(word)
			PropertyManager.getInstance().resetValues(properties)
			return result
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 3
0
 def isValid(self, word, locale, properties):
     VoikkoHandlePool.mutex.acquire()
     try:
         voikko = VoikkoHandlePool.getInstance().getHandle(locale)
         if voikko is None:
             return False
         PropertyManager.getInstance().setValues(properties)
         result = voikko.spell(word)
         PropertyManager.getInstance().resetValues(properties)
         return result
     finally:
         VoikkoHandlePool.mutex.release()
Exemplo n.º 4
0
	def removeLinguServiceEventListener(self, xLstnr):
		logging.debug("SpellChecker.removeLinguServiceEventListener")
		VoikkoHandlePool.mutex.acquire()
		try:
			return PropertyManager.getInstance().removeLinguServiceEventListener(xLstnr)
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 5
0
	def removeLinguServiceEventListener(self, xLstnr):
		logging.debug("Hyphenator.removeLinguServiceEventListener")
		VoikkoHandlePool.mutex.acquire()
		try:
			return PropertyManager.getInstance().removeLinguServiceEventListener(xLstnr)
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 6
0
	def addLinguServiceEventListener(self, xLstnr):
		logging.debug("Hyphenator.addLinguServiceEventListener")
		VoikkoHandlePool.mutex.acquire()
		try:
			return PropertyManager.getInstance().addLinguServiceEventListener(xLstnr)
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 7
0
 def addLinguServiceEventListener(self, xLstnr):
     logging.debug("SpellChecker.addLinguServiceEventListener")
     VoikkoHandlePool.mutex.acquire()
     try:
         return PropertyManager.getInstance().addLinguServiceEventListener(
             xLstnr)
     finally:
         VoikkoHandlePool.mutex.release()
Exemplo n.º 8
0
 def __init__(self, instrumentName, web_var=None):
     """ sets properties defaults for the instrument with Name"""
     self.iliad_prop = PropertyManager(instrumentName)
     # the variables which are set up from the main properties
     self._main_properties = []
     # the variables which are set up from the advanced properties.
     self._advanced_properties = []
     # The variables which are set up from web interface.
     self._web_var = web_var
Exemplo n.º 9
0
	def __initOptionsWindowFromRegistry(self, window):
		logging.debug("initOptionsWindowFromRegistry()");
		hyphWordPartsValue = False
		hyphUnknownWordsValue = True
		try:
			hyphWordPartsValue = PropertyManager.getInstance().readFromRegistry("/org.puimula.ooovoikko.Config/hyphenator",  "hyphWordParts")
			hyphUnknownWordsValue = PropertyManager.getInstance().readFromRegistry("/org.puimula.ooovoikko.Config/hyphenator", "hyphUnknownWords")
		except UnknownPropertyException as e:
			logging.exception("SettingsEventHandler: UnknownPropertyException", e)
			return
		logging.debug("hyphWordParts = " + str(hyphWordPartsValue))
		hyphWordParts = window.getControl("hyphWordParts")

		hyphWordPartsProps = hyphWordParts.getModel()
		hyphWordPartsProps.setPropertyValue("State", 1 if hyphWordPartsValue else 0)

		hyphUnknownWords = window.getControl("hyphUnknownWords")
		hyphUnknownWordsProps = hyphUnknownWords.getModel()
		hyphUnknownWordsProps.setPropertyValue("State", 1 if hyphUnknownWordsValue else 0)

		self.__initVariantDropdown(window)
Exemplo n.º 10
0
	def __saveOptionsFromWindowToRegistry(self, window):
		logging.debug("SettingsEventHandler.__saveOptionsFromWindowToRegistry")

		hyphWordParts = window.getControl("hyphWordParts")
		hyphWordPartsProps = hyphWordParts.getModel()
		hyphWordPartsValue = hyphWordPartsProps.getPropertyValue("State") # 0 = unchecked, 1 = checked

		hyphUnknownWords = window.getControl("hyphUnknownWords")
		hyphUnknownWordsProps = hyphUnknownWords.getModel()
		hyphUnknownWordsValue = hyphUnknownWordsProps.getPropertyValue("State") # 0 = unchecked, 1 = checked

		rootView = PropertyManager.getRegistryProperties("/org.puimula.ooovoikko.Config/hyphenator")
		rootView.setHierarchicalPropertyValue("hyphWordParts", hyphWordPartsValue == 1)
		rootView.setHierarchicalPropertyValue("hyphUnknownWords", hyphUnknownWordsValue == 1)
		rootView.commitChanges()

		# dictionary variant
		variantValue = self.__getSelectedVariant(window)
		rootView = PropertyManager.getRegistryProperties("/org.puimula.ooovoikko.Config/dictionary")
		rootView.setHierarchicalPropertyValue("variant", variantValue)
		rootView.commitChanges()
Exemplo n.º 11
0
	def __initVariantDropdown(self, windowContainer):
		variantDropdown = windowContainer.getControl("variant")
		variantProps = variantDropdown.getModel()

		# populate dropdown list with available variants
		self.__initAvailableVariants()
		uno.invoke(variantProps, "setPropertyValue", ("StringItemList", uno.Any("[]string", tuple(self.__dictionaryVariantList))))

		# read selected dictionary variant from registry
		registryVariantValue = "standard"
		try:
			registryVariantValue = PropertyManager.getInstance().readFromRegistry("/org.puimula.ooovoikko.Config/dictionary", "variant")
		except UnknownPropertyException as e:
			logging.exception(e)
			return
		registryVariantValue = registryVariantValue + ": "
		selectedValues = [0]
		for i, dVariant in enumerate(self.__dictionaryVariantList):
			if dVariant.startswith(registryVariantValue):
				selectedValues[0] = i;
				break;

		# set the selected item in the dropdown list
		uno.invoke(variantProps, "setPropertyValue", ("SelectedItems", uno.Any("[]short", tuple(selectedValues))))
Exemplo n.º 12
0
	def spell(self, word, locale, properties):
		# Check if diagnostic message should be returned
		if word == "VoikkoGetStatusInformation":
			suggestions = [VoikkoHandlePool.getInstance().getInitializationStatus()]
			return SpellAlternatives(word, suggestions, locale)
		
		VoikkoHandlePool.mutex.acquire()
		try:
			voikko = VoikkoHandlePool.getInstance().getHandle(locale)
			if voikko is None:
				return None

			PropertyManager.getInstance().setValues(properties)
			if voikko.spell(word):
				PropertyManager.getInstance().resetValues(properties)
				return None
			suggestions = voikko.suggest(word)
			PropertyManager.getInstance().resetValues(properties)
			return SpellAlternatives(word, suggestions, locale)
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 13
0
    def spell(self, word, locale, properties):
        # Check if diagnostic message should be returned
        if word == "VoikkoGetStatusInformation":
            suggestions = [
                VoikkoHandlePool.getInstance().getInitializationStatus()
            ]
            return SpellAlternatives(word, suggestions, locale)

        VoikkoHandlePool.mutex.acquire()
        try:
            voikko = VoikkoHandlePool.getInstance().getHandle(locale)
            if voikko is None:
                return None

            PropertyManager.getInstance().setValues(properties)
            if voikko.spell(word):
                PropertyManager.getInstance().resetValues(properties)
                return None
            suggestions = voikko.suggest(word)
            PropertyManager.getInstance().resetValues(properties)
            return SpellAlternatives(word, suggestions, locale)
        finally:
            VoikkoHandlePool.mutex.release()
Exemplo n.º 14
0
	def hyphenate(self, word, locale, nMaxLeading, properties):
		logging.debug("Hyphenator.hyphenate")
		if len(word) > 10000:
			return None
		VoikkoHandlePool.mutex.acquire()
		try:
			voikko = VoikkoHandlePool.getInstance().getHandle(locale)
			if voikko is None:
				return None
			PropertyManager.getInstance().setValues(properties)

			minLeading = PropertyManager.getInstance().getHyphMinLeading()
			minTrailing = PropertyManager.getInstance().getHyphMinTrailing()
			wlen = len(word)

			# If the word is too short to be hyphenated, return no hyphenation points
			if wlen < PropertyManager.getInstance().getHyphMinWordLength() or wlen < minLeading + minTrailing:
				PropertyManager.getInstance().resetValues(properties)
				return None

			hyphenationPoints = voikko.getHyphenationPattern(word)
			if hyphenationPoints is None:
				PropertyManager.getInstance().resetValues(properties)
				return None

			# find the hyphenation point
			hyphenPos = -1
			i = wlen - minTrailing # The last generally allowed hyphenation point
			if i > nMaxLeading:
				i = nMaxLeading # The last allowed point on this line
			while i >= minLeading and hyphenPos == -1:
				if word[i] == '\'':
					i = i - 1
					continue
				if hyphenationPoints[i] == '-' or hyphenationPoints[i] == '=':
					hyphenPos = i
					break
				i = i - 1

			# return the result
			PropertyManager.getInstance().resetValues(properties)
			if hyphenPos != -1:
				return HyphenatedWord(word, hyphenPos - 1, locale)
			else:
				return None
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 15
0
from PropertyManager import PropertyManager

if "VOIKKO_DEBUG" in os.environ:
	logging.getLogger().setLevel(logging.DEBUG)

def messageBox(messageText):
	ctx = uno.getComponentContext()
	sManager = ctx.ServiceManager
	toolkit = sManager.createInstance("com.sun.star.awt.Toolkit")
	msgbox = toolkit.createMessageBox(None, ERRORBOX, BUTTONS_OK, "Error initializing Voikko", messageText)
	return msgbox.execute()

if not PropertyManager.loadingFailed:
	try:
		# Force initialization of property manager so that it is done before anything else.
		PropertyManager.getInstance()
		# We could check for specific version but this at least ensures that libvoikko is installed
		# (this would throw an exception if it's not).
		Voikko.getVersion()
		# name of g_ImplementationHelper is significant, Python component loader expects to find it
		g_ImplementationHelper = unohelper.ImplementationHelper()
		g_ImplementationHelper.addImplementation(SettingsEventHandler, \
		                    SettingsEventHandler.IMPLEMENTATION_NAME,
		                    SettingsEventHandler.SUPPORTED_SERVICE_NAMES,)
		g_ImplementationHelper.addImplementation(SpellChecker, \
		                    SpellChecker.IMPLEMENTATION_NAME,
		                    SpellChecker.SUPPORTED_SERVICE_NAMES,)
		g_ImplementationHelper.addImplementation(Hyphenator, \
		                    Hyphenator.IMPLEMENTATION_NAME,
		                    Hyphenator.SUPPORTED_SERVICE_NAMES,)
		g_ImplementationHelper.addImplementation(GrammarChecker, \
Exemplo n.º 16
0
import os
import sys
from copy import deepcopy

from PropertyManager import PropertyManager
from utils import ValueUtils


__author__ = "Samuele Dell'Angelo (Red Hat)"


import shutil
import lxml.etree as ET

pm = PropertyManager("""Domains/domains.properties""")

base_dir = pm.getValue("domain.controller.jboss.home")

def getDomainFile(domain):
    if(os.path.isfile("domain.xml."+domain+".template")):
        tree = ET.parse("domain.xml."+domain+".template")
    else:
        tree = ET.parse('domain.xml.template')

    root = tree.getroot()
    if(root == None):
        print("domain template not present")
        exit(1)

    return tree
Exemplo n.º 17
0
	def doProofreading(self, aDocumentIdentifier, aText, aLocale, nStartOfSentencePos, nSuggestedBehindEndOfSentencePosition, aProperties):
		logging.debug("GrammarChecker.doProofreading")
		result = ProofreadingResult()
		result.aDocumentIdentifier = aDocumentIdentifier
		result.xFlatParagraph = None
		result.aText = aText
		result.aLocale = aLocale
		result.nStartOfSentencePosition = nStartOfSentencePos
		result.nBehindEndOfSentencePosition = nSuggestedBehindEndOfSentencePosition
		result.xProofreader = self

		VoikkoHandlePool.mutex.acquire()
		try:
			voikko = VoikkoHandlePool.getInstance().getHandle(aLocale)
			if voikko is None:
				logging.error("GrammarChecker.doProofreading called without initializing libvoikko")
				return result

			gcErrors = []
			gcI = 0
			vErrorCount = 0
			for vError in voikko.grammarErrors(aText, PropertyManager.getInstance().getMessageLanguage()):
				startPos = vError.startPos
				errorLength = vError.errorLen

				if startPos < result.nStartOfSentencePosition:
					continue
				if startPos >= result.nBehindEndOfSentencePosition:
					break
				if startPos + errorLength > result.nBehindEndOfSentencePosition:
					result.nBehindEndOfSentencePosition = startPos + errorLength

				# we have a real grammar error
				errorCode = vError.errorCode
				ruleIdentifier = str(errorCode)
				if ruleIdentifier in self.__ignoredErrors:
					# ignore this error
					continue

				suggestions = vError.suggestions

				gcError = SingleProofreadingError()
				gcErrors.append(gcError)
				gcError.nErrorStart = startPos
				gcError.nErrorLength = errorLength
				gcError.nErrorType = PROOFREADING
				comment = vError.shortDescription
				gcError.aShortComment = comment
				gcError.aFullComment = comment
				gcError.aRuleIdentifier = ruleIdentifier

				detailUrl = PropertyValue()
				detailUrl.Name = "FullCommentURL"
				detailUrl.Value = "https://voikko.puimula.org/gchelp/fi/" + ruleIdentifier + ".html"
				gcError.aProperties = (detailUrl,)

				# add suggestions
				if len(suggestions) > 0:
					gcError.aSuggestions = tuple(suggestions)

			result.aErrors = tuple(gcErrors)
			result.nStartOfNextSentencePosition = result.nBehindEndOfSentencePosition
			return result
		finally:
			VoikkoHandlePool.mutex.release()
Exemplo n.º 18
0
	def createPossibleHyphens(self, word, locale, properties):
		logging.debug("Hyphenator.createPossibleHyphens")
		wlen = len(word)
		if wlen > 10000:
			return None
		VoikkoHandlePool.mutex.acquire()
		try:
			voikko = VoikkoHandlePool.getInstance().getHandle(locale)
			if voikko is None:
				return None
			PropertyManager.getInstance().setValues(properties)

			# If the word is too short to be hyphenated, return no hyphenation points
			minLeading = PropertyManager.getInstance().getHyphMinLeading()
			minTrailing = PropertyManager.getInstance().getHyphMinTrailing()
			if wlen < PropertyManager.getInstance().getHyphMinWordLength() or wlen < minLeading + minTrailing:
				PropertyManager.getInstance().resetValues(properties)
				return None

			hyphenationPoints = voikko.getHyphenationPattern(word)
			if hyphenationPoints is None:
				PropertyManager.getInstance().resetValues(properties)
				return None

			hyphenSeq = []
			hyphenatedWord = ""
			for i in range(0, wlen):
				hyphenatedWord = hyphenatedWord + word[i]
				if i >= minLeading - 1 and i < wlen - minTrailing and hyphenationPoints[i + 1] == '-':
					hyphenSeq.append(i)
					hyphenatedWord = hyphenatedWord + "="

			res = PossibleHyphens(word, hyphenatedWord, hyphenSeq, locale)
			PropertyManager.getInstance().resetValues(properties)
			return res
		finally:
			VoikkoHandlePool.mutex.release()