Ejemplo n.º 1
0
func (this *Affixes) lookForAffixesInList(kind int, suff map[string]*set.Set, w *Word, dic *Dictionary) {
	var i, j, ln int
	var lws, formTerm, formRoot string
	lws = w.getLCForm()
	ln = len(lws)

	var rules *set.Set

	for i = 1; i <= this.Longest[kind] && i < ln; i++ {
		j = ln - i
		if this.ExistingLength[kind] == nil {
			TRACE(4, "No affixes  of size "+strconv.Itoa(i), MOD_AFFIX)
		} else {
			if kind == SUF {
				formTerm = lws[j:]
			} else if kind == PREF {
				formTerm = lws[0:i]
			}

			rules = suff[formTerm]
			if rules == nil || rules.Size() == 0 {
				TRACE(3, "No rules for affix "+formTerm+" (size "+strconv.Itoa(i), MOD_AFFIX)
			} else {
				TRACE(3, "Found "+strconv.Itoa(rules.Size())+" rules for affix "+formTerm+" (size "+strconv.Itoa(i), MOD_AFFIX)
				lrules := rules.List()
				for s := 0; s < rules.Size(); s++ {
					sufit := lrules[s].(*sufrule)
					if kind == SUF {
						formRoot = lws[0:j]
					} else if kind == PREF {
						formRoot = lws[i:]
					}
					TRACE(3, "Trying rule ["+formTerm+" "+sufit.term+" "+sufit.expression+" "+sufit.output+"] on root "+formRoot, MOD_AFFIX)
					candidates := this.GenerateRoots(kind, sufit, formRoot)
					this.accen.FixAccentutation(candidates, sufit)
					this.SearchRootsList(candidates, formTerm, sufit, w, dic)
				}
			}
		}
	}
}
Ejemplo n.º 2
0
func (this *Affixes) SearchRootsList(roots *set.Set, aff string, suf *sufrule, wd *Word, dic *Dictionary) {
	TRACE(3, "Checking a list of "+strconv.Itoa(roots.Size())+" roots", MOD_AFFIX)

	remain := roots.List()
	for len(remain) > 0 {
		r := remain[0]
		la := list.New()
		dic.SearchForm(r.(string), la)

		if la.Len() == 0 {
			TRACE(3, "Root "+r.(string)+" not found", MOD_AFFIX)
			roots.Remove(r)
		} else {
			TRACE(3, "Root "+r.(string)+" found in dictionary", MOD_AFFIX)
			this.ApplyRule(r.(string), la, aff, suf, wd, dic)
		}

		remain = remain[1:]
	}

}
Ejemplo n.º 3
0
func (this *Affixes) lookForCombinedAffixes(suff map[string]*set.Set, pref map[string]*set.Set, w *Word, dic *Dictionary) {
	var i, j, ln int
	var lws, formSuf, formPref, formRoot string
	lws = w.getLCForm()
	ln = len(lws)

	var rulesS *set.Set
	var rulesP *set.Set

	var candidates, cand1 *set.Set

	for i = 1; i <= this.Longest[SUF] && i < ln; i++ {
		if this.ExistingLength[SUF].Has(i) == false {
			TRACE(4, "No suffixes  of size "+strconv.Itoa(i), MOD_AFFIX)
			continue
		}

		for j = 1; j <= this.Longest[PREF] && j <= ln-i; j++ {
			if this.ExistingLength[PREF].Has(j) == false {
				TRACE(4, "No prefixes  of size "+strconv.Itoa(i), MOD_AFFIX)
				continue
			}

			formSuf = lws[ln-i:]
			formPref = lws[0:j]

			rulesS = suff[formSuf]
			if rulesS.Size() == 0 || rulesS.List()[0].(string) != formSuf {
				TRACE(3, "No rules for suffix "+formSuf+" (size "+strconv.Itoa(i), MOD_AFFIX)
				continue
			}

			rulesP = suff[formPref]
			if rulesP.Size() == 0 || rulesP.List()[0].(string) != formPref {
				TRACE(3, "No rules for prefix "+formPref+" (size "+strconv.Itoa(i), MOD_AFFIX)
				continue
			}

			formRoot = lws[0 : ln-i][j:]
			TRACE(3, "Trying a decomposition: "+formPref+"+"+formRoot+"+"+formSuf, MOD_AFFIX)

			TRACE(3, "Found "+strconv.Itoa(rulesS.Size())+" rules for suffix "+formSuf+" (size "+strconv.Itoa(i), MOD_AFFIX)
			TRACE(3, "Found "+strconv.Itoa(rulesP.Size())+" rules for prefix "+formPref+" (size "+strconv.Itoa(i), MOD_AFFIX)

			//wfid := w.foundInDict()

			lrulesS := rulesS.List()
			lrulesP := rulesP.List()

			for s := 0; s < rulesS.Size(); s++ {
				sufit := lrulesS[s].(*sufrule)
				for p := 0; p < rulesP.Size(); p++ {
					prefit := lrulesP[p].(*sufrule)
					candidates = set.New()
					cand1 = this.GenerateRoots(SUF, sufit, formRoot)
					this.accen.FixAccentutation(cand1, sufit)
					lcand1 := cand1.List()
					for _, c := range lcand1 {
						cand2 := this.GenerateRoots(PREF, prefit, c.(string))
						this.accen.FixAccentutation(cand2, prefit)
						candidates.Add(cand2)
					}
				}
			}
		}
	}
}