當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript natural.WordTokenizer類代碼示例

本文整理匯總了TypeScript中natural.WordTokenizer的典型用法代碼示例。如果您正苦於以下問題:TypeScript WordTokenizer類的具體用法?TypeScript WordTokenizer怎麽用?TypeScript WordTokenizer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了WordTokenizer類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: createTokens

function createTokens(text: string): Array<string> {
  const tokenized: Array<string> = tokenizer.tokenize(text);
  const biGrams = NGrams.ngrams(tokenized, 2).map((words) => words.join(' '));
  const triGrams = NGrams.ngrams(tokenized, 3).map((words) => words.join(' ')) as Array<string>;
  const ngrams: Array<string> = _.flatten(tokenized.concat(biGrams, triGrams)) as Array<string>;
  const allPhrases = ngrams.map(phrase => phrase.toLowerCase());
  return allPhrases;
}
開發者ID:fyndme,項目名稱:bot-framework,代碼行數:8,代碼來源:helpers.ts

示例2: getLocationConfidence

export function getLocationConfidence(text: string, searchLocation: string): number {
  let matchingCities = _.map(locations, (subLocations, key) => {
    // console.log(subLocations);
    return _.map(subLocations, (cities) => {
      // console.log(cities, searchLocation);
      const normalizedCities: Array<string> = cities.map(city => city.toLowerCase());
      return _.includes(normalizedCities, searchLocation.toLowerCase()) ? normalizedCities : null;
    });
  });

  const cityList = _.compact(_.flattenDeep<string>(matchingCities) as Array<string>);
  const allPhrases = createTokens(text);
  const matchingPhrase = _.intersection(allPhrases, cityList);

  const textTokenized: Array<string> = tokenizer.tokenize(text);
  const locationTokenized = tokenizer.tokenize(matchingPhrase[0]);

  return locationTokenized.length / textTokenized.length;
}
開發者ID:fyndme,項目名稱:bot-framework,代碼行數:19,代碼來源:helpers.ts

示例3: grabTopics

export function grabTopics(text: string): Promise<Intent> {
  const datesCompacted = runThroughClassifiers(text, dateClassifiers);
  const datesGrouped = _.groupBy(datesCompacted, 'topic');

  const specials = _.compact(tokenizer.tokenize(text).filter(token => !isNaN(parseInt(token, 10))));

  const intent: Intent = {
    action: null,
    details: {
      dates:  _.mapValues(datesGrouped, (classifications: Array<Classification>) => classifications.map(classification => _.startCase(classification.label))),
      specialWords: specials,
      locations: locatonExtractor(text),
    },
    topic: 'details',
  };

  // if (this && this.debugOn) { console.log('details intent', util.inspect(intent, { depth: null })); };

  return Promise.resolve(intent);
}
開發者ID:fyndme,項目名稱:bot-framework,代碼行數:20,代碼來源:helpers.ts


注:本文中的natural.WordTokenizer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。