欢迎大家关注 “西安e群人”微信公众号,每天会准时为您送上优质的能量养分和行业的资讯信息,为你的事业助力。
本博客唯一全国性的技术交流官方QQ群-- 互联网资源共享群英阁:658233229。 加群的朋友请按照加群提示和群公告活动,欢迎你们的到来,希望认识更多的同行业的朋友。

典型程序实现代码汇总(1)

/**
* 一个词组的单词如果是另一个词组单词的子集,就认为是个borad match,例如对于 "a b c","a", "b c" "c a" "a b c"都匹配,而 "a d"不匹配。
* 现有一个搜索匹配模块,输入为用户的查询来匹配一个词组字典,找到字典中所有可以和输入broad match的词组,输出预定的词组整型序号。
* 例如"cheap iphone in china",字典中有 1. "cheap iphone", 2. "cheap mobile", 3 "china iphone"
* @author Administrator
*
*/

package com.org.improve.contact.indexof;
public class BoradMatch {
	public static boolean isBoradMatch(String parent, String children){
		String[] childrenItems=children.split(" ");//以空格为分隔符
		for (String childrenItem:childrenItems) {
			if (parent.indexOf(childrenItem)==1) {
				return false;
			}
		}
		return true;
	}
   public static void main(String[] args) {
	 StringBuffer result=new StringBuffer();
	 String parent="cheap iphone in china";
	 String [] dicts={"cheap  iphone","cheap mobile","in  china"};
	 for (int i = 0; i < dicts.length; i++) {
		if (isBoradMatch(parent,dicts[i])) {
			result.append(",").append(i+1);
			
		}
	}
	 if (result.length()>0) {
		System.out.println("匹配的结果为:"+result.substring(1));
	} else{
		System.out.println("无任何匹配结果!");
	}
}
}

  

posted on 2015-04-04 13:14  云舜言传  阅读(159)  评论(0编辑  收藏  举报