How to use the @microsoft/recognizers-text.ParseResult function in @microsoft/recognizers-text

To help you get started, we’ve selected a few @microsoft/recognizers-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / Recognizers-Text / JavaScript / packages / recognizers-number-with-unit / src / numberWithUnit / parsers.ts View on Github external
let fractionUnitsString = '';

        for (let i = 0; i < compoundUnit.length; i++) {
            let extractResult = compoundUnit[i];
            let parseResult = this.numberWithUnitParser.parse(extractResult);
            let parseResultValue: UnitValue = parseResult.value;
            let unitValue = parseResultValue != null ? parseResultValue.unit : null;

            // Process a new group
            if (count === 0) {
                if (extractResult.type !== Constants.SYS_UNIT_CURRENCY) {
                    continue;
                }

                // Initialize a new result
                result = new ParseResult(extractResult);

                mainUnitValue = unitValue;
                if (parseResultValue.number != null) {
                    numberValue = parseFloat(parseResultValue.number);
                }
                result.resolutionStr = parseResult.resolutionStr;

                if (this.config.currencyNameToIsoCodeMap.has(unitValue)) {
                    mainUnitIsoCode = this.config.currencyNameToIsoCodeMap.get(unitValue);
                }

                // If the main unit can't be recognized, finish process this group.
                if (StringUtility.isNullOrEmpty(mainUnitIsoCode)) {
                    result.value = {
                        number: numberValue.toString(),
                        unit: mainUnitValue
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-number-with-unit / src / numberWithUnit / parsers.ts View on Github external
parse(extResult: ExtractResult): ParseResult {
        let ret = new ParseResult(extResult);
        let numberResult: ExtractResult;
        if (extResult.data && typeof extResult.data === "object") {
            numberResult = extResult.data as ExtractResult;
        }
        else if (extResult.type === Constants.SYS_NUM) {
            ret.value = this.config.internalNumberParser.parse(extResult).value;
            return ret;
        }
        else {
            // if there is no unitResult, means there is just unit
            numberResult = { start: -1, length: 0, text: null, type: null };
        }

        // key contains units
        let key = extResult.text;
        let unitKeyBuild = '';
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-number / src / number / cjkParsers.ts View on Github external
private fracParseCJK(extResult: ExtractResult): ParseResult {
        let result = new ParseResult(extResult);

        let resultText = extResult.text;
        let splitResult = RegExpUtility.split(this.config.fracSplitRegex, resultText);
        let intPart = "";
        let demoPart = "";
        let numPart = "";
        if (splitResult.length === 3) {
            intPart = splitResult[0] || "";
            demoPart = splitResult[1] || "";
            numPart = splitResult[2] || "";
        }
 else {
            intPart = this.config.zeroChar;
            demoPart = splitResult[0] || "";
            numPart = splitResult[1] || "";
        }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-number / src / number / cjkParsers.ts View on Github external
private douParseCJK(extResult: ExtractResult): ParseResult {
        let result = new ParseResult(extResult);
        
        let resultText = extResult.text;

        if (RegExpUtility.isMatch(this.config.doubleAndRoundRegex, resultText)) {
            resultText = this.replaceUnit(resultText);
            let power = this.config.roundNumberMapChar.get(resultText.charAt(resultText.length - 1));
            result.value = this.getDigitValueCJK(resultText.substr(0, resultText.length - 1), power);
        }
 else {
            resultText = this.replaceUnit(resultText);
            let splitResult = RegExpUtility.split(this.config.pointRegex, resultText);

            if (splitResult[0] === "") {
                splitResult[0] = this.config.zeroChar;
            }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-choice / src / choice / parsers.ts View on Github external
result.data.otherMatches = result.data.otherMatches.map(m => {
                let r = new ParseResult(m);
                r.value = this.config.resolutions.get(r.type);
                return r;
            });
        }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-number / src / number / cjkParsers.ts View on Github external
private intParseCJK(extResult: ExtractResult): ParseResult {
        let result = new ParseResult(extResult);
        
        result.value = this.getIntValueCJK(extResult.text);
        result.resolutionStr = this.toString(result.value);        
        return result;
    }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-sequence / src / sequence / parsers.ts View on Github external
parse(extResult: ExtractResult): ParseResult {
        let result = new ParseResult(extResult);
        result.resolutionStr = extResult.text;
        return result;
    }
}
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-number / src / number / cjkParsers.ts View on Github external
private ordParseCJK(extResult: ExtractResult): ParseResult {
        let result = new ParseResult(extResult);
        
        let resultText = extResult.text.substr(1);

        if (RegExpUtility.isMatch(this.config.digitNumRegex, resultText) && !RegExpUtility.isMatch(this.config.roundNumberIntegerRegex, resultText)) {
            result.value = this.getDigitValueCJK(resultText, 1);
        }
 else {
            result.value = this.getIntValueCJK(resultText);
        }

        result.resolutionStr = this.toString(result.value);        
        return result;
    }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-sequence / src / sequence / english / parsers.ts View on Github external
parse(extResult: ExtractResult): ParseResult {
        let result = new ParseResult(extResult);
        result.resolutionStr = extResult.text;
        result.value = this.ScorePhoneNumber(extResult.text);
        return result;
    }
}