package edu.vt.marian.server; import java.io.*; import java.net.*; import java.lang.*; import java.util.*; import edu.vt.marian.common.*; /** class name: match class description: this class parses the query strings and provides information for query. uses the services of class(es): designer(s): Jianxin Zhao (jxzhao@csgrad.cs.vt.edu) implementator(s): Jian Zeng (jizeng@vt.edu) finished time: known bugs: JDK version: 1.1.7A side effects: */ public class match { /** expected parser number */ private final static int num_parsers = 17; /** the string with exact searching conditions? */ private Vector exact_strings; /** the string with inexact searching conditions? */ private Vector inexact_strings; /** define all kind of searching flags */ private final static int exact_match_flag = 0x40000000; // used in VTLS collection private final static int cover_title_flag = 0x1; private final static int cover_subject_flag = 0x2; private final static int cover_notes_flag = 0x4; private final static int cover_personal_author_flag = 0x8; private final static int cover_corporate_author_flag = 0x10; private final static int cover_conference_author_flag = 0x20; private final static int cover_subject_entry_flag = 0x40; private final static int cover_date_flag = 0x0 ; //may be changed later. // used in NLM collection private final static int cover_address = 0x80; private final static int cover_contact_person = 0x100; private final static int cover_cross_reference = 0x200; private final static int cover_description = 0x400; private final static int cover_keywords = 0x800; private final static int cover_mesh_headings = 0x1000; private final static int cover_name = 0x2000; private final static int cover_notes = 0x4000; private final static int cover_sponsoring_agency = 0x8000; private final static int cover_type = 0x10000; /** define returned constants */ public final static int SUCCESS = 0; /** data from coverage string pair is null */ public final static int NULL_DATA = 1; /** define return value for method get_inexact_parser_flag and get_exact_parser_flag */ public final static int INVALID_PARSER_FLAG = -1; /** define debug object */ private Debug debug; /** method description: this constructor will create a match object with empty exact and inexact string. uses the services of class(es): Debug input parameter(s): debug -- used for debugging. output parameter(s): none return value: none synchronization consideration: none */ public match(Debug debug) { int i; String temp = null; this.debug = debug; exact_strings = new Vector(); inexact_strings = new Vector(); for (i = 0; i < num_parsers; i++) { // create an empty string, and add it to exact_strings temp = new String(""); exact_strings.addElement(temp); // create an empty string, and add it to inexact_strings temp = new String(""); inexact_strings.addElement(temp); } return; } /** method description: this method will return the number of parsers uses the services of class(es): input parameter(s): none output parameter(s): none return value: the number of parsers synchronization consideration: none */ public int get_number_parsers() { return num_parsers; } /** method description: this method constructs exact or inexact string from the converage string pair. uses the services of class(es): input parameter(s): csp --- this coverage string pair output parameter(s): none return value: SUCCESS -- execute correctly NULL_DATA -- data from coverage string pair is null synchronization consideration: this is a synchronized method because writing to the exact and inexact string */ public synchronized int add(coverage_string_pair csp) { String data = null; int coverage; int i; int exponent = 1; //this varaible is used to calculte 2^i. String s = null; //to store the ith element of vector // get data from csp data = csp.get_data(); if ((data == null) || (data.equals(""))) { debug.dumpTrace("In class match, method add, data from the " + "coverage string pair is null or empty."); return NULL_DATA; } coverage = csp.get_coverage(); if ( (coverage & exact_match_flag) != 0) { //deal with exact strings for (i = 0; i < num_parsers; i++) { if ( (coverage & exponent) != 0) { // coverage & 2^i = 1 s = (String) exact_strings.elementAt(i); s = s + data + " "; exact_strings.setElementAt(s, i); } exponent = exponent << 1; } } else { // for inexact_strings //deal with inexact strings for (i = 0; i < num_parsers; i++) { if ( (coverage & exponent) != 0) { s = (String) inexact_strings.elementAt(i); s = s + data + " "; inexact_strings.setElementAt(s, i); } exponent = exponent << 1; } } return SUCCESS; } /** method description: this method will return the an element (string) from the inexact string uses the services of class(es): input parameter(s): parser_index --- the index of the parser output parameter(s): none return value: the element of the inexact string which locates at parser_index. synchronization consideration: none */ public String get_inexact_string(int parser_index) { if ((parser_index >= 0) && (parser_index < num_parsers)) { String s = (String) inexact_strings.elementAt(parser_index); return s; } // parser_index is out of range. debug.dumpTrace("In class match, method get_inexact_string, " + "parser index out of range."); return null; } /** method description: this method will return the an element (string) from the exact string uses the services of class(es): input parameter(s): parser_index --- the index of the parser output parameter(s): none return value: the element of the exact string which locates at parser_index. synchronization consideration: none */ public String get_exact_string(int parser_index) { if ((parser_index >= 0) && (parser_index < num_parsers)) { String s = (String) exact_strings.elementAt(parser_index); return s; } // parser_index out of range debug.dumpTrace("In class match, method get_exact_string, " + "parser index out of range."); return null; } /** method description: this method will return the inexact parser flag. uses the services of class(es): input parameter(s): parser_index --- the index of the parser output parameter(s): none return value: correct- the inexact parser flag according to the parser index INVALID_PARSER_FLAG - parser_index is invalid synchronization consideration: none */ public int get_inexact_parser_flag(int parser_index) { if ((parser_index >= 0) && (parser_index < num_parsers)) { int i; int exponent = 1; for (i = 0; i < parser_index; i++) { exponent = exponent << 1; } return exponent; } // parser_index out of range debug.dumpTrace("In class match, method get_inexact_parser_flag, " + "parser index out of range."); return INVALID_PARSER_FLAG; } /** method description: this method will return the exact parser flag. uses the services of class(es): input parameter(s): parser_index --- the index of the parser output parameter(s): none return value: correct -- the exact parser flag according to the parser index INVALID_PARSER_FLAG -- parser_index is invalid synchronization consideration: none */ public int get_exact_parser_flag(int parser_index) { if ((parser_index >= 0) && (parser_index < num_parsers)) { int i; int exponent = 1; for (i = 0; i < parser_index; i++) { exponent = exponent << 1; } return (exponent | exact_match_flag); } // parser_index out of range debug.dumpTrace("In class match, method get_exact_parser_flag, " + "parser index out of range."); return INVALID_PARSER_FLAG; } /** method description: this method will return the value of the cover title flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover title flag synchronization consideration: none */ public int get_cover_title_flag() { return cover_title_flag; } /** method description: this method will return the value of the cover subject flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover subject flag synchronization consideration: none */ public int get_cover_subject_flag() { return cover_subject_flag; } /** method description: this method will return the value of the cover notes flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover notes flag synchronization consideration: none */ public int get_cover_notes_flag() { return cover_notes_flag; } /** method description: this method will return the value of the cover personal author flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover personal author flag synchronization consideration: none */ public int get_cover_personal_author_flag() { return cover_personal_author_flag; } /** method description: this method will return the value of the cover corporate author flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover corporate author flag synchronization consideration: none */ public int get_cover_corporate_author_flag() { return cover_corporate_author_flag; } /** method description: this method will return the value of the cover conference author flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover conference author flag synchronization consideration: none */ public int get_cover_conference_author_flag() { return cover_conference_author_flag; } /** method description: this method will return the value of the cover subject entry flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the cover subject entry flag synchronization consideration: none */ public int get_cover_subject_entry_flag() { return cover_subject_entry_flag; } /** method description: this method will return the value of the date flag uses the services of class(es): input parameter(s): none output parameter(s): none return value: the value of the date flag synchronization consideration: none */ public int get_date_flag() { return cover_date_flag; } }