/** * Copyright (c) 2006 by Know-Center, Graz, Austria * * This software is the confidential and proprietary information of Know-Center, * Graz, Austria. You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Know-Center. * * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. * * $Id: FoundBlock.java,v 1.2 2006/10/31 08:07:29 wprinz Exp $ */ package at.knowcenter.wag.egov.egiz.framework; import java.util.ArrayList; import java.util.List; import at.knowcenter.wag.egov.egiz.sig.SignatureTypeDefinition; import at.knowcenter.wag.egov.egiz.sig.SignatureTypes; /** * Contains all the information about a found Block in text extracton. * *

* This is basically the ordered list of found captions. *

* * @author wprinz */ public class FoundBlock { /** * The ordered list of found keys. */ public List found_keys = null; /** * The end index of the block. */ public int end_index = 0; /** * The type of the block. */ public SignatureTypeDefinition std = null; /** * Returns the first key of this block. * * @return Returns the first key of this block. */ public FoundKey getFirstKey() { return (FoundKey) this.found_keys.get(found_keys.size() - 1); } /** * Returns the last key of this block. * * @return Returns the last key of this block. */ public FoundKey getLastKey() { return (FoundKey) this.found_keys.get(0); } /** * Returns the size of this block. * *

* Note that this doesn't give the exact size of the block, but rather a value * suirable for comparison. *

* * @return Returns the size of this block. */ public int getSize() { int size = getLastKey().start_index - getFirstKey().start_index; return size; } /** * @see java.lang.Object#toString() */ public String toString() { return "FoundBlock: std=" + this.std.getType() + ", #=" + this.found_keys.size() + ", size = " + getSize(); } /** * Tells, if this block is semantically equal to the other block. * * Two blocks are semantically equal, if all the required have the * same captions in the same order. * * @param other_block * The other block. * @return Returns true, of this block is semantically equal to the other one, * false otherwise. */ public boolean isSemanticallyEqual(FoundBlock other_block) { List this_keys = filterOutNonRequiredFoundKeys(this.found_keys); List other_keys = filterOutNonRequiredFoundKeys(other_block.found_keys); if (this_keys.size() != other_keys.size()) { return false; } for (int i = 0; i < this_keys.size(); i++) { FoundKey this_found_key = (FoundKey) this_keys.get(i); FoundKey other_found_key = (FoundKey) other_keys.get(i); if (!this_found_key.isSemanticallyEqual(other_found_key)) { return false; } } return true; } /** * Filters out all non required keys from the List of found keys. * * @param found_keys The List of found keys. * * @return Rturns the subset List which contains only the required keys. */ protected static List filterOutNonRequiredFoundKeys (List found_keys) { List required_found_keys = new ArrayList(found_keys.size()); for (int i = 0; i < found_keys.size(); i++) { FoundKey this_found_key = (FoundKey) found_keys.get(i); if (!SignatureTypes.isRequiredKey(this_found_key.key)) { continue; } required_found_keys.add(this_found_key); } return required_found_keys; } /** * Tells, if this block is strictly semantically equal to the other block. * * Two blocks are strictly semantically equal, if they contain the same keys with the * same captions in the same order. * * @param other_block * The other block. * @return Returns true, of this block is semantically equal to the other one, * false otherwise. */ public boolean isStrictlySemanticallyEqual(FoundBlock other_block) { if (this.found_keys.size() != other_block.found_keys.size()) { return false; } for (int i = 0; i < this.found_keys.size(); i++) { FoundKey this_found_key = (FoundKey) this.found_keys.get(i); FoundKey other_found_key = (FoundKey) other_block.found_keys.get(i); if (!this_found_key.isSemanticallyEqual(other_found_key)) { return false; } } return true; } public FoundKey getDateFoundKey () { for (int i = 0; i < this.found_keys.size(); i++) { FoundKey found_key = (FoundKey) this.found_keys.get(i); if (found_key.key.equals(SignatureTypes.SIG_DATE)) { return found_key; } } throw new RuntimeException("There is no SIG_DATE in the list of found_keys. This must not happen."); } }