How to use the @microsoft/recognizers-text.ExtractResult.isOverlap 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-date-time / src / dateTime / baseDateTime.ts View on Github external
let er2 = this.config.timeExtractor.extract(text, referenceTime);
        if (er2.length === 0) {
            // here we filter out "morning, afternoon, night..." time entities
            er2 = this.config.timeExtractor.extract(this.config.tokenBeforeTime + text, referenceTime);
            if (er2.length === 1) {
                er2[0].start -= this.config.tokenBeforeTime.length;
            }
            else {
                return ret;
            }
        }

        // handle case "Oct. 5 in the afternoon at 7:00"
        // in this case "5 in the afternoon" will be extract as a Time entity
        let correctTimeIdx = 0;
        while (correctTimeIdx < er2.length && ExtractResult.isOverlap(er2[correctTimeIdx], er1[0])) {
            correctTimeIdx++;
        }

        if (correctTimeIdx >= er2.length) {
            return ret;
        }

        let pr1 = this.config.dateParser.parse(er1[0], new Date(referenceTime.toDateString()));
        let pr2 = this.config.timeParser.parse(er2[correctTimeIdx], referenceTime);
        if (pr1.value === null || pr2.value === null) {
            return ret;
        }

        let futureDate = pr1.value.futureValue;
        let pastDate = pr1.value.pastValue;
        let time = pr2.value.futureValue;
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / baseDateTimePeriod.ts View on Github external
protected mergeTwoTimePoints(source: string, referenceDate: Date): DateTimeResolutionResult {
        let result = new DateTimeResolutionResult();
        let prs: { begin: DateTimeParseResult, end: DateTimeParseResult };
        let timeErs = this.config.timeExtractor.extract(source, referenceDate);
        let datetimeErs = this.config.dateTimeExtractor.extract(source, referenceDate);
        let bothHasDate = false;
        let beginHasDate = false;
        let endHasDate = false;

        if (datetimeErs.length === 2) {
            prs = this.getTwoPoints(datetimeErs[0], datetimeErs[1], this.config.dateTimeParser, this.config.dateTimeParser, referenceDate);
            bothHasDate = true;
        }
        else if (datetimeErs.length === 1 && timeErs.length === 2) {
            if (ExtractResult.isOverlap(datetimeErs[0], timeErs[0])) {
                prs = this.getTwoPoints(datetimeErs[0], timeErs[1], this.config.dateTimeParser, this.config.timeParser, referenceDate);
                beginHasDate = true;
            }
            else {
                prs = this.getTwoPoints(timeErs[0], datetimeErs[0], this.config.timeParser, this.config.dateTimeParser, referenceDate);
                endHasDate = true;
            }
        }
        else if (datetimeErs.length === 1 && timeErs.length === 1) {
            if (timeErs[0].start < datetimeErs[0].start) {
                prs = this.getTwoPoints(timeErs[0], datetimeErs[0], this.config.timeParser, this.config.dateTimeParser, referenceDate);
                endHasDate = true;
            }
            else {
                prs = this.getTwoPoints(datetimeErs[0], timeErs[0], this.config.dateTimeParser, this.config.timeParser, referenceDate);
                beginHasDate = true;
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / chinese / dateTimePeriodConfiguration.ts View on Github external
private mergeDateAndTimePeriod(source: string, refDate: Date): Token[] {
        let tokens: Token[] = new Array();
        let ersDate = this.config.singleDateExtractor.extract(source, refDate);
        let ersTime = this.config.singleTimeExtractor.extract(source, refDate);
        let timeResults = new Array();
        let j = 0;
        for (let i = 0; i < ersDate.length; i++) {
            timeResults.push(ersDate[i]);
            while (j < ersTime.length && ersTime[j].start + ersTime[j].length <= ersDate[i].start) {
                timeResults.push(ersTime[j]);
                j++;
            }

            while (j < ersTime.length && ExtractResult.isOverlap(ersTime[j], ersDate[i])) {
                j++;
            }
        }

        for (j; j < ersTime.length; j++) {
            timeResults.push(ersTime[j]);
        }
        timeResults = timeResults.sort((a, b) => a.start > b.start ? 1 : a.start < b.start ? -1 : 0);

        let idx = 0;
        while (idx < timeResults.length - 1) {
            let current = timeResults[idx];
            let next = timeResults[idx + 1];
            if (current.type === Constants.SYS_DATETIME_DATE && next.type === Constants.SYS_DATETIME_TIMEPERIOD) {
                let middleBegin = current.start + current.length;
                let middleEnd = next.start;
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / baseMerged.ts View on Github external
destination.forEach((dest, index) => {
                if (ExtractResult.isOverlap(dest, value)) {
                    isFound = true;
                    if (ExtractResult.isCover(dest, value)) {
                        if (firstIndex === -1) {
                            firstIndex = index;
                        }
                        overlapIndexes.push(index);
                    }
                    else {
                        return;
                    }
                }
            });
            if (!isFound) {
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / chinese / dateTimePeriodConfiguration.ts View on Github external
protected mergeTwoTimePoints(text: string, referenceTime: Date): DateTimeResolutionResult {
        let result = new DateTimeResolutionResult();
        let prs: { begin: DateTimeParseResult, end: DateTimeParseResult };
        let timeErs = this.config.timeExtractor.extract(text, referenceTime);
        let datetimeErs = this.config.dateTimeExtractor.extract(text, referenceTime);
        let bothHasDate = false;
        let beginHasDate = false;
        let endHasDate = false;

        if (datetimeErs.length === 2) {
            prs = this.getTwoPoints(datetimeErs[0], datetimeErs[1], this.config.dateTimeParser, this.config.dateTimeParser, referenceTime);
            bothHasDate = true;
        }
        else if (datetimeErs.length === 1 && timeErs.length === 2) {
            if (ExtractResult.isOverlap(datetimeErs[0], timeErs[0])) {
                prs = this.getTwoPoints(datetimeErs[0], timeErs[1], this.config.dateTimeParser, this.config.timeParser, referenceTime);
                beginHasDate = true;
            }
            else {
                prs = this.getTwoPoints(timeErs[0], datetimeErs[0], this.config.timeParser, this.config.dateTimeParser, referenceTime);
                endHasDate = true;
            }
        }
        else if (datetimeErs.length === 1 && timeErs.length === 1) {
            if (timeErs[0].start < datetimeErs[0].start) {
                prs = this.getTwoPoints(timeErs[0], datetimeErs[0], this.config.timeParser, this.config.dateTimeParser, referenceTime);
                endHasDate = true;
            }
            else {
                prs = this.getTwoPoints(datetimeErs[0], timeErs[0], this.config.dateTimeParser, this.config.timeParser, referenceTime);
                beginHasDate = true;
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / baseDateTime.ts View on Github external
protected mergeDateAndTime(source: string, refDate: Date): Token[] {
        let tokens: Token[] = new Array();
        let ers = this.config.datePointExtractor.extract(source, refDate);
        if (ers.length < 1) {
            return tokens;
        }
        ers = ers.concat(this.config.timePointExtractor.extract(source, refDate));
        if (ers.length < 2) {
            return tokens;
        }
        ers = ers.sort((erA, erB) => erA.start < erB.start ? -1 : erA.start === erB.start ? 0 : 1);
        let i = 0;
        while (i < ers.length - 1) {
            let j = i + 1;
            while (j < ers.length && ExtractResult.isOverlap(ers[i], ers[j])) {
                j++;
            }
            if (j >= ers.length) {
                break;
            }
            if ((ers[i].type === Constants.SYS_DATETIME_DATE && ers[j].type === Constants.SYS_DATETIME_TIME) ||
                (ers[i].type === Constants.SYS_DATETIME_TIME && ers[j].type === Constants.SYS_DATETIME_DATE)) {
                let middleBegin = ers[i].start + ers[i].length;
                let middleEnd = ers[j].start;
                if (middleBegin > middleEnd) {
                    i = j + 1;
                    continue;
                }
                let middleStr = source.substr(middleBegin, middleEnd - middleBegin).trim().toLowerCase();
                if (this.config.isConnectorToken(middleStr)) {
                    let begin = ers[i].start;
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / baseDateTimePeriod.ts View on Github external
ersDateTime.forEach((erDateTime, index) => {
            innerMarks.push(erDateTime);
            while (j < ersTime.length && ersTime[j].start + ersTime[j].length < erDateTime.start) {
                innerMarks.push(ersTime[j++]);
            }
            while (j < ersTime.length && ExtractResult.isOverlap(ersTime[j], erDateTime)) {
                j++;
            }
        });
        while (j < ersTime.length) {
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / chinese / dateTimeConfiguration.ts View on Github external
protected mergeDateAndTime(source: string, refDate: Date): Token[] {
        let tokens: Token[] = new Array();
        let ers = this.config.datePointExtractor.extract(source, refDate);
        if (ers.length < 1) {
            return tokens;
        }
        ers = ers.concat(this.config.timePointExtractor.extract(source, refDate));
        if (ers.length < 2) {
            return tokens;
        }
        ers = ers.sort((erA, erB) => erA.start < erB.start ? -1 : erA.start === erB.start ? 0 : 1);
        let i = 0;
        while (i < ers.length - 1) {
            let j = i + 1;
            while (j < ers.length && ExtractResult.isOverlap(ers[i], ers[j])) {
                j++;
            }
            if (j >= ers.length) {
                break;
            }
            if (ers[i].type === Constants.SYS_DATETIME_DATE && ers[j].type === Constants.SYS_DATETIME_TIME) {
                let middleBegin = ers[i].start + ers[i].length;
                let middleEnd = ers[j].start;
                if (middleBegin > middleEnd) {
                    continue;
                }
                let middleStr = source.substr(middleBegin, middleEnd - middleBegin).trim().toLowerCase();
                if (this.config.isConnectorToken(middleStr)) {
                    let begin = ers[i].start;
                    let end = ers[j].start + ers[j].length;
                    tokens.push(new Token(begin, end));
github microsoft / Recognizers-Text / JavaScript / packages / recognizers-date-time / src / dateTime / chinese / dateTimePeriodConfiguration.ts View on Github external
ersDateTime.forEach((erDateTime, index) => {
            innerMarks.push(erDateTime);
            while (j < ersTime.length && ersTime[j].start + ersTime[j].length < erDateTime.start) {
                innerMarks.push(ersTime[j++]);
            }
            while (j < ersTime.length && ExtractResult.isOverlap(ersTime[j], erDateTime)) {
                j++;
            }
        });