proper.imp
Class CSVParser

java.lang.Object
  extended by proper.core.ProperObject
      extended by proper.imp.Parser
          extended by proper.imp.CSVParser
All Implemented Interfaces:
ProperInterface, ParserInterface

public class CSVParser
extends Parser

This parser works on CSV files. Handwritten parser was necessary, since JLex/CUP had problems with big files...
NOTE: It discards cells that contain non-ASCII or whitespace (except blank) characters, because of RELAGGS.

Version:
$Revision: 1.2 $
Author:
FracPete

Field Summary
static java.lang.String FILE_PREDICATE
          the predicate name of the current file
static java.lang.String IDENTIFIER_PREDICATE
          the predicate name of the identifiers
 
Fields inherited from class proper.imp.Parser
RELAGGS_FIX
 
Fields inherited from interface proper.imp.ParserInterface
CLASS_NEGATIVE, CLASS_POSITIVE
 
Fields inherited from interface proper.core.ProperInterface
VERSION
 
Constructor Summary
CSVParser()
          initializes the object
 
Method Summary
 boolean getHasIdentifiers()
          returns whether there are any identifiers in the first line
 java.lang.String getPredicateName()
          returns the name for this predicates
 char getQualifier()
          returns the qualifier for strings (default: ")
 char getSeparator()
          returns the separator for the columns (default: ,)
 boolean getTreatEmptyAsNull()
          returns whether we treat empty cells as NULL values
static void main(java.lang.String[] args)
          for testing only
 void parse(java.io.BufferedReader reader)
          uses the given buffered reader to parse the file
 void parse(java.io.Reader reader)
          uses the given reader to parse the file
 void setHasIdentifiers(boolean hasIdentifiers)
          sets whether we have any identifiers in the first line
 void setPredicateName(java.lang.String name)
          sets the name for the predicates in this file (automatically lower case)
 void setPredicateName(java.lang.String name, boolean lowercase)
          sets the name for the predicates in this file, can be AS IS or lower case
 void setQualifier(char qualifier)
          sets the qualifier for strings (default: ")
 void setQualifier(java.lang.String qualifier)
          sets the qualifier for strings (default: ")
 void setSeparator(char separator)
          sets the separator for the columns (default: ,)
 void setSeparator(java.lang.String separator)
          sets the separator for the columns (default: ,), 'tab' is interpreted as '\t'
 void setTreatEmptyAsNull(boolean treatEmptyAsNull)
          sets whether we treat empty cells as NULL values
 
Methods inherited from class proper.imp.Parser
clear, getAddClassLabel, getClassLabel, getFilename, getOnlyForSingles, getPredicates, parse, setAddClassLabel, setClassLabel, setFilename, setID, setOnlyForSingles, toString
 
Methods inherited from class proper.core.ProperObject
addListener, addOutput, classInVerbose, debugprint, debugprint, debugprint, debugprint, debugprintln, debugprintln, debugprintln, debugprintln, debugprintln, getListeners, getRuntime, getVerbose, getVerboseLevel, getVerboseLevelForClass, getVerboseString, getVerboseStringForClass, notifyListener, notifyListeners, print, print, print, print, println, println, println, println, println, printMemory, removeListener, setOutput, setVerbose, setVerboseLevel, setVerboseString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface proper.imp.ParserInterface
getVerbose, setVerbose
 

Field Detail

FILE_PREDICATE

public static java.lang.String FILE_PREDICATE
the predicate name of the current file


IDENTIFIER_PREDICATE

public static java.lang.String IDENTIFIER_PREDICATE
the predicate name of the identifiers

Constructor Detail

CSVParser

public CSVParser()
initializes the object

Method Detail

setPredicateName

public void setPredicateName(java.lang.String name)
sets the name for the predicates in this file (automatically lower case)


setPredicateName

public void setPredicateName(java.lang.String name,
                             boolean lowercase)
sets the name for the predicates in this file, can be AS IS or lower case


getPredicateName

public java.lang.String getPredicateName()
returns the name for this predicates


setHasIdentifiers

public void setHasIdentifiers(boolean hasIdentifiers)
sets whether we have any identifiers in the first line


getHasIdentifiers

public boolean getHasIdentifiers()
returns whether there are any identifiers in the first line


setSeparator

public void setSeparator(java.lang.String separator)
sets the separator for the columns (default: ,), 'tab' is interpreted as '\t'


setSeparator

public void setSeparator(char separator)
sets the separator for the columns (default: ,)


getSeparator

public char getSeparator()
returns the separator for the columns (default: ,)


setQualifier

public void setQualifier(java.lang.String qualifier)
sets the qualifier for strings (default: ")


setQualifier

public void setQualifier(char qualifier)
sets the qualifier for strings (default: ")


getQualifier

public char getQualifier()
returns the qualifier for strings (default: ")


setTreatEmptyAsNull

public void setTreatEmptyAsNull(boolean treatEmptyAsNull)
sets whether we treat empty cells as NULL values


getTreatEmptyAsNull

public boolean getTreatEmptyAsNull()
returns whether we treat empty cells as NULL values


parse

public void parse(java.io.BufferedReader reader)
           throws java.lang.Exception
uses the given buffered reader to parse the file

Throws:
java.lang.Exception

parse

public void parse(java.io.Reader reader)
           throws java.lang.Exception
uses the given reader to parse the file

Specified by:
parse in interface ParserInterface
Overrides:
parse in class Parser
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
for testing only

Throws:
java.lang.Exception