How to use the @microsoft/recognizers-text.ExtractResult 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 / extractors.ts View on Github external
continue;
            }

            // Separated by connectors
            let match = RegExpUtility.getMatches(this.config.compoundUnitConnectorRegex, middleStr).pop();
            if (match && match.index === 0 && match.length === middleStr.length) {
                groups[i + 1] = groups[i];
            }
            else {
                groups[i + 1] = groups[i] + 1;
            }
        }

        for (let i = 0; i < ers.length; i++) {
            if (i === 0 || groups[i] !== groups[i - 1]) {
                let tmpInner = new ExtractResult();
                tmpInner.data = ers[i].data;
                tmpInner.length = ers[i].length;
                tmpInner.start = ers[i].start;
                tmpInner.text = ers[i].text;
                tmpInner.type = ers[i].type;

                let tmpExtractResult = ers[i];
                tmpExtractResult.data = new Array();
                tmpExtractResult.data.push(tmpInner);

                result.push(tmpExtractResult);
            }

            // Reduce extract results in same group
            if (i + 1 < ers.length && groups[i + 1] === groups[i]) {
                let group = groups[i];
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / baseDatePeriod.ts View on Github external
private getYearFromText(match: Match): number {
        let firstTwoYearNumStr = match.groups('firsttwoyearnum').value;
        if (!StringUtility.isNullOrEmpty(firstTwoYearNumStr)) {
            let er = new ExtractResult();
            er.text = firstTwoYearNumStr;
            er.start = match.groups('firsttwoyearnum').index;
            er.length = match.groups('firsttwoyearnum').length;

            let firstTwoYearNum = Number.parseInt(this.config.numberParser.parse(er).value);

            let lastTwoYearNum = 0;
            let lastTwoYearNumStr = match.groups('lasttwoyearnum').value;
            if (!StringUtility.isNullOrEmpty(lastTwoYearNumStr)) {
                er.text = lastTwoYearNumStr;
                er.start = match.groups('lasttwoyearnum').index;
                er.length = match.groups('lasttwoyearnum').length;

                lastTwoYearNum = Number.parseInt(this.config.numberParser.parse(er).value);
            }
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / baseDatePeriod.ts View on Github external
protected mergeTwoTimePoints(source: string, refDate: Date): Token[] {
        let tokens: Token[] = new Array();
        let er = this.config.datePointExtractor.extract(source, refDate);
        if (er.length <= 1) {
            let matches = RegExpUtility.getMatches(this.config.nowRegex, source);
            if (matches.length) {
                let nowEr = new ExtractResult();
                nowEr.start = matches[0].index;
                nowEr.length = matches[0].length;
                er.push(nowEr);
                er = er.sort((x, y) => (x.start - y.start));
            }
            else {
                return tokens;
            }

        }

        let idx = 0;
        while (idx < er.length - 1) {
            let middleBegin = er[idx].start + (er[idx].length || 0);
            let middleEnd = er[idx + 1].start || 0;
            if (middleBegin >= middleEnd) {