Example #1
0
 def __del__(self):
     print "Deleting", self.__class__
     if self._po is not None:
         clg.parse_options_delete(self._po)
         self._po = None
Example #2
0
	def __del__(self):
		#print "Deleting",self.__class__
		if self._po is not None:
			clg.parse_options_delete(self._po)
			self._po = None
Example #3
0
    def parse(self, dic):
        pErr = None
        szSent = self.sText

        sent = clg.sentence_create(self.sText, dic)
        self.nwords = clg.sentence_length(sent)

        opts = clg.parse_options_create()
        clg.parse_options_set_disjunct_cost(opts, 2)
        clg.parse_options_set_min_null_count(opts, 0)
        clg.parse_options_set_max_null_count(opts, 0)
        clg.parse_options_set_islands_ok(opts, 0)
        clg.parse_options_set_panic_mode(opts, 1)
        clg.parse_options_reset_resources(opts)
        num_linkages = clg.sentence_parse(sent, opts)

        res = (num_linkages >= 1)
        if (not res and (num_linkages == 0)):
            clg.parse_options_set_min_null_count(opts, 1)
            clg.parse_options_set_max_null_count(opts,
                                                 clg.sentence_length(sent))
            clg.parse_options_set_islands_ok(opts, 1)
            clg.parse_options_reset_resources(opts)
            num_linkages = clg.sentence_parse(sent, opts)

        self.bGrammarChecked = 1
        self.bGrammarOK = res

        if (not res):
            if (num_linkages > 0):
                linkage = clg.linkage_create(0, sent, opts)
                if (linkage != None):
                    i = 0
                    iLow = 0
                    iHigh = 0
                    iOff = self.iInLow
                    totlen = len(self.sText)
                    i = 1
                    while (i < clg.sentence_length(sent) and (iLow < totlen)):
                        while ((szSent[iLow] == ' ') and (iLow < totlen)):
                            iLow = iLow + 1
                        if (iLow >= totlen):
                            break
                        iHigh = iLow + len(clg.sentence_get_nth_word(sent, i))
                        self.addVecMapOfWords(
                            iLow, iHigh, i, clg.sentence_get_nth_word(sent, i))
                        bNew = 0
                        if (not clg.sentence_nth_word_has_disjunction(sent,
                                                                      i)):
                            if (not pErr):
                                pErr = {}
                                bNew = 1
                            if (bNew or (pErr["iWordNum"] + 1 < i)):
                                if (not bNew):
                                    if (pErr):
                                        pErr = None
                                    pErr = {}
                                iHigh = iLow + len(
                                    clg.sentence_get_nth_word(sent, i))
                                pErr["iErrLow"] = iLow + iOff - 1
                                pErr["iErrHigh"] = iHigh + iOff - 1
                                if (pErr["iErrLow"] < 0):
                                    pErr["iErrLow"] = 0
                                if (pErr["iErrHigh"] < totlen - 1):
                                    pErr["iErrHigh"] += 1
                                pErr["word"] = clg.sentence_get_nth_word(
                                    sent, i)
                                pErr["iWordNum"] = i
                                self.grammarErrors.append(pErr)
                                pErr = None
                            else:
                                iHigh = iLow + strlen(
                                    clg.sentence_get_nth_word(sent, i)) + iOff
                                pErr["iErrHigh"] = iHigh
                                if (pErr["iErrHigh"] < totlen - 1):
                                    pErr["iErrHigh"] += 1
                                pErr["iWordNum"] = i
                        iLow += len(clg.sentence_get_nth_word(sent, i))
                        i = i + 1

                    if (len(self.grammarErrors) == 0):
                        if (pErr):
                            pErr = None
                        pErr = {}
                        pErr["iErrLow"] = self.iInLow
                        pErr["iErrHigh"] = self.iInHigh
                        pErr["iWordNum"] = -1
                        pErr["sErrorDesc"] = clg.linkage_get_violation_name(
                            linkage)
                        if (pErr["iErrLow"] < 0):
                            pErr["iErrLow"] = 0
                        self.grammarErrors.append(pErr)
                        pErr = None
                    sErr = clg.linkage_get_violation_name(linkage)
                    clg.linkage_delete(linkage)
            else:
                if (pErr):
                    pErr = None
                pErr = {}
                pErr["iErrLow"] = self.iInLow
                pErr["iErrHigh"] = self.iInHigh
                if (pErr["iErrLow"] < 0):
                    pErr["iErrLow"] = 0
                self.grammarErrors.append(pErr)
                pErr = None
            if (pErr):
                pErr = None
        clg.parse_options_delete(opts)
        clg.sentence_delete(sent)