⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility.java

📁 ictclas java实现 很不错的 包含全部所需的文件包 能对句子进行详细的词法分析.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				else {
					if (b1.length - i >= b2.length) {
						for (int j = 0; j < b2.length; j++) {
							if (b2[j] != b1[i + j]) {
								flag = false;
								break;
							}
						}

						if (flag) {
							return i;
						}
					}
				}
			}
		}

		return -1;
	}

	public static int strchr(byte[] bs, byte b) {
		if (bs != null) {
			for (int i = 0; i < bs.length; i++) {
				if (bs[i] == b)
					return i;
			}

		}

		return -1;
	}

	/**
	 * 比较两个字节数组前len个字节是否相等
	 * 
	 * @param b1
	 * @param b2
	 * @param len
	 * @return
	 */
	public static boolean strncmp(byte[] b1, int startIndex, byte[] b2, int len) {
		if (b1 != null && b2 != null && len > 0) {
			if (b1.length >= len && b2.length >= len) {
				for (int i = startIndex; i < len; i++) {
					if (b1[i] != b2[i])
						return true;
				}
			}
		}

		return false;
	}

	public static int getUnsigned(byte b) {
		if (b > 0)
			return (int) b;
		else
			return (b& 0x7F+128);
	}

	public static void strncpy(byte[] dest, byte[] src, int len) {
		if (dest != null && src != null) {
			if (dest.length >= len && len <= src.length) {
				for (int i = 0; i < len; i++)
					dest[i] = src[i];
			}
		}
	}

	/**
	 * 汉字在6768区位表中对应的ID号
	 */
	public static int CC_ID(String str) {
		int result = -1;
		if (str != null && str.length() > 0) {
			byte[] b = str.getBytes();
			result = (getUnsigned(b[0]) - 176) * 94 + (getUnsigned(b[1]) - 161);
		}
		return result;
	}

	/**
	 * The first char computed by the Chinese Char ID
	 * 
	 * @param id
	 * @return
	 */
	public static int CC_CHAR1(int id) {
		return (id) / 94 + 176;
	}

	/**
	 * The second char computed by the Chinese Char ID
	 * 
	 * @param id
	 * @return
	 */
	public static int CC_CHAR2(int id) {
		return (id) % 94 + 161;
	}

	public static int strcat(byte[] dest, byte[] src, int len) {
		if (dest != null && src != null && len > 0) {

			for (int i = 0; i < dest.length; i++) {
				if (dest[i] == 0) {
					for (int j = 0; j < len; j++)
						dest[i] = src[j];
					return i;
				}
			}

		}

		return -1;
	}

	public static int strcpy(byte[] dest, byte[] src) {
		return strcpy(dest, src, src.length);
	}

	public static int strcpy(byte[] dest, byte[] src, int len) {
		if (dest != null && src != null && len > 0) {
			int i = 0;
			for (i = 0; i < len; i++) {
				dest[i] = src[i];

			}
			return i;
		}

		return -1;
	}

	/**
	 * 根据ID号得到对应的GB汉字
	 * 
	 * @param id
	 *            0--6767
	 * @return
	 */
	public static String getGB(int id) {
		String result = null;

		if (id >= 0 && id < 6768) {
			byte[] b = new byte[2];
			b[0] = (byte) CC_CHAR1(id);
			b[1] = (byte) CC_CHAR2(id);
			try {
				result = new String(b, "GBK");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return result;
	}

	/**
	 * 把SegGraph插入的列表当中
	 * 
	 * @param sgs
	 * @param graph
	 * @param isRowFirst
	 *            是否按行优先原则
	 * @return 如果插入成功返回True,否则返回False
	 */
	public static boolean insertGraph(ArrayList<SegNode> sgs, SegNode graph, boolean isRowFirst) {
		SegNode sg = null;

		if (sgs != null && graph != null) {
			if (sgs.size() == 0) {
				sgs.add(graph);
				return true;
			}

			for (int i = 0; i < sgs.size(); i++) {
				sg = sgs.get(i);

				if (isRowFirst) {
					// 到最后一个节点
					if (i == sgs.size() - 1) {
						if (graph.getRow() > sg.getRow()
								|| (graph.getRow() == sg.getRow() && graph.getCol() > sg.getCol()))
							sgs.add(graph);
						else {
							if (graph.getCol() == sg.getCol()) {
								sgs.set(i, graph);
								return false;
							} else
								sgs.add(i, graph);
						}
						return true;
					}

					if (graph.getRow() > sg.getRow() || (graph.getRow() == sg.getRow() && graph.getCol() > sg.getCol()))
						continue;
					else {
						if (graph.getCol() == sg.getCol()) {
							sgs.set(i, graph);
							return false;
						} else
							sgs.add(i, graph);

						return true;
					}
				} else {
					// 到最后一个节点
					if (i == sgs.size() - 1) {
						if (graph.getCol() > sg.getCol()
								|| (graph.getCol() == sg.getCol() && graph.getRow() > sg.getRow()))
							sgs.add(graph);
						else {
							if (graph.getRow() == sg.getRow()) {
								sgs.set(i, graph);
								return false;
							} else
								sgs.add(i, graph);
						}
						return true;
					}

					if (graph.getCol() > sg.getCol() || (graph.getCol() == sg.getCol() && graph.getRow() > sg.getRow()))
						continue;
					else {
						if (graph.getRow() == sg.getRow()) {
							sgs.set(i, graph);
							return false;
						} else
							sgs.add(i, graph);

						return true;
					}
				}
			}
		}

		return false;
	}

	/**
	 * 得到下一个行值和该列值相等的所有元素。
	 * 
	 * @param sgs
	 * @param curIndex
	 *            当前元素的位置
	 * @return
	 */
	public static ArrayList<SegNode> getNextElements(ArrayList<SegNode> sgs, int curIndex) {
		ArrayList<SegNode> result = null;

		if (sgs != null && sgs.size() > 0 && curIndex >= 0 && curIndex < sgs.size()) {
			result = new ArrayList<SegNode>();
			SegNode curSg = sgs.get(curIndex);

			for (int i = curIndex + 1; i < sgs.size(); i++) {
				SegNode sg = sgs.get(i);
				if (sg.getRow() == curSg.getCol())
					result.add(sg);

			}
		}
		return result;
	}

	/**
	 * 得到所有列值为Col的元素
	 * 
	 * @param sgs
	 * @param col
	 *            列值
	 * @return
	 */
	public static ArrayList<SegNode> getColElements(ArrayList<SegNode> sgs, int col) {
		ArrayList<SegNode> result = null;

		if (sgs != null && sgs.size() > 0 && col >= 0) {
			result = new ArrayList<SegNode>(); 
			for (int i = 0; i < sgs.size(); i++) {
				SegNode sg = sgs.get(i);
				if (sg.getCol() == col)
					result.add(sg);

			}
		}
		return result;
	}
	
	/**
	 * 取得指定行值、列值的元素
	 * @param sgs
	 * @param row
	 * @param col
	 * @return
	 */
	public static SegNode getElement(ArrayList<SegNode> sgs,int row,int col){
		 
		if(sgs!=null&&sgs.size()>0){
			for(SegNode sg:sgs){
				if(sg.getRow()==row &&( sg.getCol()==col||  col==-1))
					return sg;
			}
		}
		return null;
	}

	public static boolean isSingle(String s) {
		if (s != null && s.getBytes().length == 1)
			return true;
		else
			return false;
	}

	public static int[] removeInvalid(int[] src) {
		int[] result = null;
		int count = 0;
		if (src != null && src.length > 0) {
			for (int i = 0; i < src.length; i++) {
				if (i != 0 && src[i] == 0)
					break;
				else
					count++;
			}

			result = new int[count];
			for (int i = 0; i < count; i++)
				result[i] = src[i];
		}

		return result;
	}

	/**
	 * 判断字符串是否是年份
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isYearTime(String snum) {
		if (snum != null) {
			int len = snum.length();
			String first = snum.substring(0, 1);

			// 1992年, 98年,06年
			if (isAllSingleByte(snum)
					&& (len == 4 || len == 2 && (GFString.cint(first) > 4 || GFString.cint(first) == 0)))
				return true;
			if (isAllNum(snum) && (len >= 6 || len == 4 && "056789".indexOf(first) != -1))
				return true;
			if (getCharCount("零○一二三四五六七八九壹贰叁肆伍陆柒捌玖", snum) == len && len >= 2)
				return true;
			if (len == 4 && getCharCount("千仟零○", snum) == 2)// 二仟零二年
				return true;
			if (len == 1 && getCharCount("千仟", snum) == 1)
				return true;
			if (len == 2 && getCharCount("甲乙丙丁戊己庚辛壬癸", snum) == 1
					&& getCharCount("子丑寅卯辰巳午未申酉戌亥", snum.substring(1)) == 1)
				return true;
		}
		return false;
	}
	
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -