当前位置: 首页>>代码示例>>Java>>正文


Java Metaphone类代码示例

本文整理汇总了Java中org.apache.commons.codec.language.Metaphone的典型用法代码示例。如果您正苦于以下问题:Java Metaphone类的具体用法?Java Metaphone怎么用?Java Metaphone使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Metaphone类属于org.apache.commons.codec.language包,在下文中一共展示了Metaphone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
@Override
public TokenStream create(TokenStream tokenStream) {
	if (BEIDER_MORSE.equals(codec))
		return new BeiderMorseTokenFilter(tokenStream, new EncoderKey(
				ruleType, maxPhonemes));
	if (COLOGNE_PHONETIC.equals(codec))
		return new EncoderTokenFilter(tokenStream, new ColognePhonetic());
	if (SOUNDEX.equals(codec))
		return new EncoderTokenFilter(tokenStream, new Soundex());
	if (REFINED_SOUNDEX.equals(codec))
		return new EncoderTokenFilter(tokenStream, new RefinedSoundex());
	if (METAPHONE.equals(codec))
		return new EncoderTokenFilter(tokenStream, new Metaphone());
	if (CAVERPHONE1.equals(codec))
		return new EncoderTokenFilter(tokenStream, new Caverphone1());
	if (CAVERPHONE2.equals(codec))
		return new EncoderTokenFilter(tokenStream, new Caverphone2());
	return null;
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:20,代码来源:PhoneticFilter.java

示例2: testFactory

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Case: default
 */
public void testFactory() throws IOException {
  Map<String,String> args = new HashMap<String, String>();
  
  PhoneticFilterFactory ff = new PhoneticFilterFactory();
  
  args.put( PhoneticFilterFactory.ENCODER, "Metaphone" );
  ff.init( args );
  ff.inform(new ClasspathResourceLoader(ff.getClass()));
  assertTrue( ff.getEncoder() instanceof Metaphone );
  assertTrue( ff.inject ); // default

  args.put( PhoneticFilterFactory.INJECT, "false" );
  ff.init( args );
  ff.inform(new ClasspathResourceLoader(ff.getClass()));
  assertFalse( ff.inject );

  args.put( PhoneticFilterFactory.MAX_CODE_LENGTH, "2");
  ff.init(args);
  ff.inform(new ClasspathResourceLoader(ff.getClass()));
  assertEquals(2, ((Metaphone) ff.getEncoder()).getMaxCodeLen());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:TestPhoneticFilterFactory.java

示例3: isWordCommand

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * <p>
 * isWordCommand.
 * </p>
 *
 * @param argDef a {@link com.obdobion.argument.type.ICmdLineArg} object.
 * @return a boolean.
 */
public boolean isWordCommand(final ICmdLineArg<?> argDef)
{
    if (argDef.getKeyword() == null || isUsed() || !isWordCommand() || getValue().length() < 3)
        return false;
    if (getWordCommand().length() == argDef.getKeyword().length())
    {
        if (getWordCommand().equalsIgnoreCase(argDef.getKeyword()))
            return true;
    } else if (getWordCommand().length() < argDef.getKeyword().length())
    {
        if (argDef.getKeyword().substring(0, getWordCommand().length()).equalsIgnoreCase(getWordCommand()))
            return true;
        if (argDef.isCamelCapsAllowed())
            /*
             * Check for camel caps
             */
            if (argDef.getCamelCaps() != null)
                if (argDef.getCamelCaps().equalsIgnoreCase(getWordCommand()))
                    return true;
        if (argDef.isMetaphoneAllowed())
            /*
             * Check for metaphone
             */
            if (argDef.getMetaphone() != null)
                if (new Metaphone().metaphone(getWordCommand()).equals(argDef.getMetaphone()))
                    return true;
    }
    return false;
}
 
开发者ID:fedups,项目名称:com.obdobion.argument,代码行数:38,代码来源:Token.java

示例4: testFactoryDefaults

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Case: default
 */
public void testFactoryDefaults() throws IOException {
  Map<String,String> args = new HashMap<>();
  args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertTrue(factory.getEncoder() instanceof Metaphone);
  assertTrue(factory.inject); // default
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:TestPhoneticFilterFactory.java

示例5: testMaxCodeLength

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
public void testMaxCodeLength() throws IOException {
  Map<String,String> args = new HashMap<>();
  args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
  args.put(PhoneticFilterFactory.MAX_CODE_LENGTH, "2");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertEquals(2, ((Metaphone) factory.getEncoder()).getMaxCodeLen());
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:TestPhoneticFilterFactory.java

示例6: testFactoryReflection

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Case: Reflection
 */
public void testFactoryReflection() throws IOException {
  Map<String,String> args = new HashMap<>();
  args.put(PhoneticFilterFactory.ENCODER, "org.apache.commons.codec.language.Metaphone");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertTrue(factory.getEncoder() instanceof Metaphone);
  assertTrue(factory.inject); // default
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:TestPhoneticFilterFactory.java

示例7: doCall

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
public Boolean doCall() throws Exception {
	
	MungeStepOutput<String> out = getOut();
	MungeStepOutput<String> in = getMSOInputs().get(0);
	String data = in.getData();
	if (data != null) {
		out.setData(new Metaphone().metaphone(data));
	} else {
		out.setData(null);
	}
	return true;
}
 
开发者ID:SQLPower,项目名称:power-matchmaker,代码行数:13,代码来源:MetaphoneMungeStep.java

示例8: loadData

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
static Map<String, List<String>> loadData() throws IOException {
//		log.info("loading POS tag dictionary...");
		Metaphone _metaphone = new Metaphone();
		_metaphone.setMaxCodeLen(100);
        HashMap<String, List<String>> wordToPos  =
                new HashMap<String, List<String>>();
		BufferedReader in = BasicFileIO.getResourceReader("res/arktweetnlp/tagdict.txt");
		String line;
        try {
            while((line = in.readLine()) != null) {
                String[] parts = line.trim().split("\t");
                if (parts.length != 2) {
                    System.out.println(parts.length);
                    System.out.println("wtf " + line.trim() + " | " + parts.length);
                    continue;
                }
                String word = parts[0];
                String poses = parts[1].trim();
                ArrayList<String> arr = new ArrayList(); //new String[poses.length()];
                for (int i=0; i < poses.length(); i++) {
                    arr.add(poses.substring(i,i+1));
                }
                wordToPos.put(word, Collections.unmodifiableList(arr));
}
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return Collections.unmodifiableMap(wordToPos);
	}
 
开发者ID:weizh,项目名称:geolocator-3.0,代码行数:30,代码来源:TagDictionary.java

示例9: testFactoryCaseReflection

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Case: Reflection
 */
public void testFactoryCaseReflection() throws IOException {
  Map<String,String> args = new HashMap<String, String>();
  
  PhoneticFilterFactory ff = new PhoneticFilterFactory();
  ClasspathResourceLoader loader = new ClasspathResourceLoader(ff.getClass());

  args.put( PhoneticFilterFactory.ENCODER, "org.apache.commons.codec.language.Metaphone" );
  ff.init( args );
  ff.inform( loader );
  assertTrue( ff.getEncoder() instanceof Metaphone );
  assertTrue( ff.inject ); // default

  // we use "Caverphone2" as it is registered in the REGISTRY as Caverphone,
  // so this effectively tests reflection without package name
  args.put( PhoneticFilterFactory.ENCODER, "Caverphone2" );
  ff.init( args );
  ff.inform( loader );
  assertTrue( ff.getEncoder() instanceof Caverphone2 );
  assertTrue( ff.inject ); // default
  
  // cross check with registry
  args.put( PhoneticFilterFactory.ENCODER, "Caverphone" );
  ff.init( args );
  ff.inform( loader );
  assertTrue( ff.getEncoder() instanceof Caverphone2 );
  assertTrue( ff.inject ); // default
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:31,代码来源:TestPhoneticFilterFactory.java

示例10: testFactoryDefaults

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Case: default
 */
public void testFactoryDefaults() throws IOException {
  Map<String,String> args = new HashMap<String,String>();
  args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertTrue(factory.getEncoder() instanceof Metaphone);
  assertTrue(factory.inject); // default
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:12,代码来源:TestPhoneticFilterFactory.java

示例11: testMaxCodeLength

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
public void testMaxCodeLength() throws IOException {
  Map<String,String> args = new HashMap<String,String>();
  args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
  args.put(PhoneticFilterFactory.MAX_CODE_LENGTH, "2");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertEquals(2, ((Metaphone) factory.getEncoder()).getMaxCodeLen());
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:9,代码来源:TestPhoneticFilterFactory.java

示例12: testFactoryReflection

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Case: Reflection
 */
public void testFactoryReflection() throws IOException {
  Map<String,String> args = new HashMap<String, String>();
  args.put(PhoneticFilterFactory.ENCODER, "org.apache.commons.codec.language.Metaphone");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertTrue(factory.getEncoder() instanceof Metaphone);
  assertTrue(factory.inject); // default
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:12,代码来源:TestPhoneticFilterFactory.java

示例13: getEncodedMF

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
private String getEncodedMF( String value, Integer algorithmType ) {
  String encodedValueMF = "";
  switch ( algorithmType ) {
    case FuzzyMatchMeta.OPERATION_TYPE_METAPHONE:
      encodedValueMF = ( new Metaphone() ).metaphone( value );
      break;
    case FuzzyMatchMeta.OPERATION_TYPE_DOUBLE_METAPHONE:
      encodedValueMF = ( ( new DoubleMetaphone() ).doubleMetaphone( value ) );
      break;
    case FuzzyMatchMeta.OPERATION_TYPE_SOUNDEX:
      encodedValueMF = ( new Soundex() ).encode( value );
      break;
    case FuzzyMatchMeta.OPERATION_TYPE_REFINED_SOUNDEX:
      encodedValueMF = ( new RefinedSoundex() ).encode( value );
      break;
    default:
      break;
  }
  return encodedValueMF;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:21,代码来源:FuzzyMatch.java

示例14: PhoneticTokenFilterFactory

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
public PhoneticTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
    super(indexSettings, name, settings);
    this.languageset = null;
    this.nametype = null;
    this.ruletype = null;
    this.maxcodelength = 0;
    this.replace = settings.getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), "replace", true, deprecationLogger);
    // weird, encoder is null at last step in SimplePhoneticAnalysisTests, so we set it to metaphone as default
    String encodername = settings.get("encoder", "metaphone");
    if ("metaphone".equalsIgnoreCase(encodername)) {
        this.encoder = new Metaphone();
    } else if ("soundex".equalsIgnoreCase(encodername)) {
        this.encoder = new Soundex();
    } else if ("caverphone1".equalsIgnoreCase(encodername)) {
        this.encoder = new Caverphone1();
    } else if ("caverphone2".equalsIgnoreCase(encodername)) {
        this.encoder = new Caverphone2();
    } else if ("caverphone".equalsIgnoreCase(encodername)) {
        this.encoder = new Caverphone2();
    } else if ("refined_soundex".equalsIgnoreCase(encodername) || "refinedSoundex".equalsIgnoreCase(encodername)) {
        this.encoder = new RefinedSoundex();
    } else if ("cologne".equalsIgnoreCase(encodername)) {
        this.encoder = new ColognePhonetic();
    } else if ("double_metaphone".equalsIgnoreCase(encodername) || "doubleMetaphone".equalsIgnoreCase(encodername)) {
        this.encoder = null;
        this.maxcodelength = settings.getAsInt("max_code_len", 4);
    } else if ("bm".equalsIgnoreCase(encodername) || "beider_morse".equalsIgnoreCase(encodername) || "beidermorse".equalsIgnoreCase(encodername)) {
        this.encoder = null;
        this.languageset = settings.getAsArray("languageset");
        String ruleType = settings.get("rule_type", "approx");
        if ("approx".equalsIgnoreCase(ruleType)) {
            ruletype = RuleType.APPROX;
        } else if ("exact".equalsIgnoreCase(ruleType)) {
            ruletype = RuleType.EXACT;
        } else {
            throw new IllegalArgumentException("No matching rule type [" + ruleType + "] for beider morse encoder");
        }
        String nameType = settings.get("name_type", "generic");
        if ("GENERIC".equalsIgnoreCase(nameType)) {
            nametype = NameType.GENERIC;
        } else if ("ASHKENAZI".equalsIgnoreCase(nameType)) {
            nametype = NameType.ASHKENAZI;
        } else if ("SEPHARDIC".equalsIgnoreCase(nameType)) {
            nametype = NameType.SEPHARDIC;
        }
    } else if ("koelnerphonetik".equalsIgnoreCase(encodername)) {
        this.encoder = new KoelnerPhonetik();
    } else if ("haasephonetik".equalsIgnoreCase(encodername)) {
        this.encoder = new HaasePhonetik();
    } else if ("nysiis".equalsIgnoreCase(encodername)) {
        this.encoder = new Nysiis();
    } else if ("daitch_mokotoff".equalsIgnoreCase(encodername)) {
        this.encoder = new DaitchMokotoffSoundex();
    } else {
        throw new IllegalArgumentException("unknown encoder [" + encodername + "] for phonetic token filter");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:58,代码来源:PhoneticTokenFilterFactory.java

示例15: executeCustomCommand

import org.apache.commons.codec.language.Metaphone; //导入依赖的package包/类
/**
 * Method to iterate through the voice data and attempt to match the user's custom commands
 * using the {@link Metaphone} within ranges applied by the associated thresholds constants.
 *
 * @return the highest scoring {@link CustomCommand} or null if thresholds aren't satisfied
 */
public CustomCommand executeCustomCommand() {

    long then = System.nanoTime();

    final double jwdLowerThreshold = SPH.getJaroWinklerLower(mContext);
    CustomCommand customCommand = null;
    final ArrayList<CustomCommandContainer> toKeep = new ArrayList<>();
    final Metaphone metaphone = new Metaphone();
    final JaroWinklerDistance jwd = new JaroWinklerDistance();

    String phrase;
    CustomCommandContainer container;
    double score;
    boolean matches;

    int size = genericData.size();

    outer:
    for (int i = 0; i < size; i++) {
        container = (CustomCommandContainer) genericData.get(i);
        phrase = container.getKeyphrase().toLowerCase(loc).trim();

        for (String vd : inputData) {
            vd = vd.toLowerCase(loc).trim();
            matches = metaphone.isMetaphoneEqual(phrase, vd);

            if (matches && Algorithm.checkLength(phrase, vd)) {
                score = jwd.apply(phrase, vd);

                if (score > jwdLowerThreshold) {

                    container.setScore(score);
                    container.setUtterance(vd);
                    container.setExactMatch(true);
                    toKeep.add(SerializationUtils.clone(container));
                    break outer;
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "Matches: double check JW: rejected");
                    }
                }
            }
        }
    }

    if (UtilsList.notNaked(toKeep)) {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "Have a match");
        }

        final CustomCommandContainer ccc = toKeep.get(0);

        final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        customCommand = gson.fromJson(ccc.getSerialised(), CustomCommand.class);
        customCommand.setExactMatch(ccc.isExactMatch());
        customCommand.setUtterance(ccc.getUtterance());
        customCommand.setAlgorithm(Algorithm.METAPHONE);
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "no custom phrases matched");
        }
    }

    if (DEBUG) {
        MyLog.getElapsed(CLS_NAME, then);
    }

    return customCommand;
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:76,代码来源:MetaphoneHelper.java


注:本文中的org.apache.commons.codec.language.Metaphone类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。