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

📄 cdynamicarray.java

📁 基于中科院的ICTCLAS实现中文分词系统 开发工具是JAVA.经测试,效果很好
💻 JAVA
字号:
package com.gftech.ictclas4j.segment;

import java.util.ArrayList;

import com.gftech.ictclas4j.utility.Final;
import com.gftech.ictclas4j.utility.Utility;

public class CDynamicArray {
	public int m_nCol, m_nRow;// The row and col of the array

	public boolean m_bRowFirst;

	public TagQueueElem s;

	private ArrayList<TagArrayChain> m_pHead;// The head pointer of array
												// chain

	public boolean SetRowFirst(boolean RowFirst) {
		m_bRowFirst=RowFirst;
		return true;
	}

	public boolean SetRowFirst() {
		return SetRowFirst(true);
	}

	// Get the tail Element buffer and return the count of elements
	public TagArrayChain GetTail() {  
		return m_pHead.get(m_pHead.size()-1);
	}

	public TagArrayChain[] GetHead() {
		return null;
	}

	public int SetElement(int nRow, int nCol, double fValue, int nPOS,
			byte[] sWord) {
		ArrayList<TagArrayChain> pCur = new ArrayList<TagArrayChain>();
		for (TagArrayChain tac : m_pHead)
			pCur.add(tac);

		if (nRow > m_nRow)// Set the array row
			m_nRow = nRow;
		if (nCol > m_nCol)// Set the array col
			m_nCol = nCol;

		int index = 0;
		TagArrayChain tac = null;
		if (m_bRowFirst) {
			for (int i = 0; i < pCur.size(); i++) {
				tac = pCur.get(i);
				if (tac.row < nRow || (tac.row == nRow && tac.col < nCol))
					index++;

			}
		} else {
			for (int i = 0; i < pCur.size(); i++) {
				if (tac.col < nCol || (tac.col == nCol && tac.row < nRow))
					index++;
			}
		}

		// Find the same position
		tac = pCur.get(index);
		if (index < pCur.size() && tac.row == nRow && tac.col == nCol) {
			tac.value = fValue;// Set the value
			tac.nPOS = nPOS;// Set the possible POS
		} else {
			TagArrayChain tac2 = new TagArrayChain(); // node
			tac2.col = nCol;// get the value
			tac2.row = nRow;
			tac2.value = fValue;
			tac2.nPOS = nPOS;
			if (sWord != null)// sWord is not empty
			{
				tac2.nWordLen = sWord.length;
				tac2.sWord = new byte[tac2.nWordLen + 1];
				Utility.strcpy(tac2.sWord, sWord);
			} else// sWord is Empty
			{
				tac2.nWordLen = 0;
				tac2.sWord = null;
			}
			pCur.add(index, tac2);
		}
		return 0;
	} // Get the head Element

	public boolean GetElement(int nRow, int nCol, double pRetValue,
			int pRetPOS, byte[] sRetWord) {
		return false;
	}

	public void SetEmpty() {
		ArrayList<TagArrayChain> pCur = m_pHead;
		TagArrayChain tac = null;
		for (int i = 0; i < pCur.size(); i++)// delete the node
		{
			tac = pCur.get(i);
			if (tac.nWordLen > 0) {
				pCur.remove(i);
				i--;
			}
		}
		m_pHead = null; 
		m_nCol = 0;
		m_nRow = 0;
	}

	public CDynamicArray() {
		new CDynamicArray(false);
	}

	public CDynamicArray(boolean bRowFirst) {
		m_nRow = 0;
		m_nCol = 0;
		m_bRowFirst = bRowFirst;
	}

	public double GetElement(int nRow, int nCol,
			ArrayList<TagArrayChain> pStart, TagArrayChain[] pRet) {
		ArrayList<TagArrayChain> pCur = pStart;
		if (pStart == null)
			pCur = m_pHead;
		if (pRet != null && pRet.length > 0)
			pRet[0] = null;

		if (nRow > m_nRow || nCol > m_nCol)// Judge if the row and col is
			// overflow
			return Final.INFINITE_VALUE;

		int i = 0;
		TagArrayChain tac = null;
		if (m_bRowFirst) {
			for (i = 0; i < pCur.size(); i++) {
				tac = pCur.get(i);
				if (nRow != -1 && tac.row < nRow
						|| (nCol != -1 && tac.row == nRow && tac.col < nCol)) {
					if (pRet != null && pRet.length > 0) {
						// *pRet=pCur;
					}
				}
			}
		} else {
			for (i = 0; i < pCur.size(); i++) {
				tac = pCur.get(i);
				if (nCol != -1
						&& (tac.col < nCol || (tac.col == nCol && nRow != -1 && tac.row < nRow))) {
					if (pRet != null) {
						// *pRet=pCur;
					}
				}
			}
		}

		// Find the same position
		if (i < pCur.size() && (pCur.get(i).row == nRow || nRow == -1)
				&& (pCur.get(i).col == nCol || nCol == -1)) {// Find it and
			// return the value
			if (pRet != null) {
				// *pRet=pCur;
			}
			return pCur.get(i).value;
		}
		return Final.INFINITE_VALUE;
	}

}

⌨️ 快捷键说明

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