How to convert serialClob to String format? - java

I am trying to convert serialclob to string. But I am not successful. I think I am not doing in the correct way. My code is:
char[] buffer;
int count = 0;
int length = 0;
String data = null;
String[] type;
StringBuffer sb;
try{
SqlRowSet rows = getJdbcTemplate().queryForRowSet("select c.BOUNDING_BOX.GET_WKT() BOUNDING_BOX FROM EXAMPLE c WHERE EXAMPLE_ID = 100",
new Object[] {subid});
SubscriptionModel subscription = new SubscriptionModel();
System.out.println("bbox");
SqlRowSetMetaData rsmd = rows.getMetaData();
type = new String[rsmd.getColumnCount()];
for(int col=0;col<rsmd.getColumnCount();col++)
type[col] = rsmd.getColumnTypeName(col + 1);
System.out.println("Read rows and only serial clob data type values");
while(rows.next()){
System.out.println("test 1 here");
for(int col=0;col<rsmd.getColumnCount();col++){
System.out.println("test 2 here");
if("CLOB".equals(type[col]){
System.out.println("test 3 here");
SerialClob clob = (SerialClob) ((ResultSet) rows).getClob(col + 1);
if(clob != null){
System.out.println("clob is not null");
Reader is = clob.getCharacterStream();
sb = new StringBuffer();
length = (int) clob.length();
if(length>0){
buffer = new char[length];
count = 0;
try{
while((count = is.read(buffer)) != -1)
sb.append(buffer);
data = new String(sb);
}catch(Exception e){
}
}
else
data = (String) null;
}else
data = (String) null;
}else{
data = (String) rows.getObject(col + 1);
}
}
}
return subscription;
}catch(Exception e){
e.printStackTrace();
}
But I am getting an error like:
bbox
Read rows and only serial clob data type values
test 1 here
test 2 here
java.lang.ClassCastException: javax.sql.rowset.serial.SerialClob cannot be cast to java.lang.String
Where is my mistake?

Well this is at least one problem:
if(type[col] == "CLOB")
That's comparing string references directly. I suspect this would work better:
if ("CLOB".equals(type[col]))
That will get you into the right if block. I haven't looked in detail at the rest of your code - it would be simpler to read and maintain if you could break it up into smaller methods.

The problem is most likely here --
if(type[col] == "CLOB"){ // <-- This does Object equality
Use String#equals() method to do String comparisons.
if ( "CLOB".equals(type[col]) ) {

Related

Conversion Error in TEIID during function call

I have following function defined in a java jar file within the vdb folder:
public static Blob createSampleLogCurve(String indexType, String indexUnit, String curveName, String curveUnit, String curveDataType, Object depthArray, Object valueArray) throws BulkDataException, SQLException { NullValueDef nullDef = new NullValueDef();
byte[] bytes = null;
nullDef.setNullFloat(-98765.0F);
double[] depths = (double[])((double[])depthArray);
int totalsamples = depths.length;
String dataType = DataType.FLOAT.toString();
double increment = depths[1] - depths[0];
for(int i = 0; i < totalsamples - 1; ++i) {
if (increment != depths[i + 1] - depths[i]) {
increment = 0.0D;
break;
}
}
if (curveDataType.equalsIgnoreCase("INT")) {
dataType = DataType.INT.toString();
} else if (curveDataType.equalsIgnoreCase("DOUBLE")) {
dataType = DataType.DOUBLE.toString();
} else {
dataType = DataType.FLOAT.toString();
}
CurveIndexProtoBuf indexProtobuf = new CurveIndexProtoBuf(depths[0], increment, totalsamples, indexType, indexUnit, depths);
List<CurveValueProtoBuf> values = new ArrayList();
values.add(new CurveValueProtoBuf(SampleType.VALUE.toString(), dataType, (String)null, curveUnit, 1, 1, (List)null, curveName, (Index)null, (Index)null, valueArray));
LogCurveProtoBuf logCurveProtobuf = new LogCurveProtoBuf(indexType.equals("DEPTH") ? IndexType.DEPTH.toString() : IndexType.TIME.toString(), indexProtobuf, values);
PipedInputStream in = new PipedInputStream(1024);
PipedOutputStream out = null;
try {
out = new PipedOutputStream(in);
logCurveProtobuf.build().writeDelimitedTo(out);
out.close();
bytes = IOUtils.toByteArray(in);
} catch (Exception var29) {
System.out.println(var29);
} finally {
try {
out.close();
in.close();
} catch (IOException var28) {
var28.printStackTrace();
}
}
return new SerialBlob(bytes)
}
This is how I have declared the UDF in DDL
CREATE VIRTUAL FUNCTION createSampleLogCurve(indexType string, indexUnit string, curveName string, curveUnit string, curveDataType string, depthArray double[], valueArray float[]) returns Blob
OPTIONS(JAVA_CLASS 'com.common.udf.ProtoBufFunctions', JAVA_METHOD 'createSampleLogCurve');
When I call the function from SQL client, I get below error. I also tried object and object[]
java.lang.ClassCastException: org.teiid.core.types.ArrayImpl cannot be cast to [D
Appreciate any help on this
Thanks
The issue is with this line
double[] depths = (double[])((double[])depthArray);
Either try changing the method signature to use double[] depthArray if that does not work, try casting to ArrayImpl like
either one of the above solutions will work!
if (depthArray instanceof ArrayImpl) {
ArrayImpl array = (ArrayImpl) depth array;
Object[] arrayVals = array.getValues();
for (int i = 0; i < arrayVals.length; i++) {
double val = arrayVals[i];
// do
}
}
one of the above solutions should work!

How to Verify Mobile no and email id from Secure QR code of Aadhaar card

Official Document for How to Read QR code data from Secure QR code of UIDAI Aadhaar card: https://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf
Have used zxing scanner to scan Secure QR code,
And was able to get details of aadhar card with the help of follow project in Github:
https://github.com/dimagi/AadharUID
Some how I figured out how to extract photo and bit_indicator_value from converted byte array with the help of instructions on document
But I am unable to get hashed exact hashed value of email and mobile from Secure QR code of Aadhar card byte array to verify
I am bit confused from this line of above mentioned document in page no 6:
Post getting signature value, check the value of
Email_mobile_present_bit_indicator_value:
if its 3 then first read mobile from index (Byte array length – 1-256) and then email from index (Byte array length – 1- 256- 32) in
reverse order. Each value will be of fix size of 32 byte.
If Email_mobile_present_bit_indicator_value is 1 then only mobile
is present.
If Email_mobile_present_bit_indicator_value is 2 then only email is
present.
If Email_mobile_present_bit_indicator_value is 0 then no mobile or
email present.
Email and Mobile value will available in byte. Convert into Hexadecimal
String.
.
I have also prepared last step in document page no 6 but the users mobile/email hash value and documents mobile/email byte arrays hash value never matches
Code snippet:
public ScanResult(String input) {
rawString = input;
// copied from http://www.java-samples.com/showtutorial.php?tutorialid=152
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document dom;
try {
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// Replace </?xml... with <?xml...
if (input.startsWith("</?")) {
input = input.replaceFirst("</\\?", "<?");
}
// Replace <?xml...?"> with <?xml..."?>
input = input.replaceFirst("^<\\?xml ([^>]+)\\?\">", "<?xml $1\"?>");
//parse using builder to get DOM representation of the XML file
dom = db.parse(new ByteArrayInputStream(input.getBytes("UTF-8")));
} catch (ParserConfigurationException | SAXException | IOException e) {
dom = null;
}
if (rawString.matches("[0-9]*")) {
type = QR_CODE_TYPE_SECURE;
byte[] msgInBytes = null;
try {
msgInBytes = decompressByteArray(new BigInteger(rawString).toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
if (msgInBytes != null) {
int[] delimiters = locateDelimiters(msgInBytes);
String referenceId = getValueInRange(msgInBytes, delimiters[0] + 1, delimiters[1]);
uid = referenceId.substring(0, 4);
name = getValueInRange(msgInBytes, delimiters[1] + 1, delimiters[2]);
dob = formatDate(getValueInRange(msgInBytes, delimiters[2] + 1, delimiters[3]),
new String[] {"dd-MM-yyyy", "dd/MM/yyyy"});
yob = dob.substring(0, 4);
gender = getValueInRange(msgInBytes, delimiters[3] + 1, delimiters[4]);
co = getValueInRange(msgInBytes, delimiters[4] + 1, delimiters[5]);
dist = getValueInRange(msgInBytes, delimiters[5] + 1, delimiters[6]);
lm = getValueInRange(msgInBytes, delimiters[6] + 1, delimiters[7]);
house = getValueInRange(msgInBytes, delimiters[7] + 1, delimiters[8]);
loc = getValueInRange(msgInBytes, delimiters[8] + 1, delimiters[9]);
pc = getValueInRange(msgInBytes, delimiters[9] + 1, delimiters[10]);
po = getValueInRange(msgInBytes, delimiters[10] + 1, delimiters[11]);
state = getValueInRange(msgInBytes, delimiters[11] + 1, delimiters[12]);
street = getValueInRange(msgInBytes, delimiters[12] + 1, delimiters[13]);
subdist = getValueInRange(msgInBytes, delimiters[13] + 1, delimiters[14]);
vtc = getValueInRange(msgInBytes, delimiters[14] + 1, delimiters[15]);
statusCode = STATUS_SUCCESS;
} else {
statusCode = STATUS_PARSE_ERROR;
uid = "";
name = "";
gender = "";
yob = "";
co = "";
house = "";
street = "";
lm = "";
loc = "";
vtc = "";
po = "";
dist = "";
subdist = "";
state = "";
pc = "";
dob = "";
}
} else {
type = QR_CODE_TYPE_UNKNOWN;
statusCode = STATUS_PARSE_ERROR;
uid = "";
name = "";
gender = "";
yob = "";
co = "";
house = "";
street = "";
lm = "";
loc = "";
vtc = "";
po = "";
dist = "";
subdist = "";
state = "";
pc = "";
dob = "";
}
dobGuess = getDobGuess(dob, yob);
statusText = getStatusText(statusCode);
}
private static int[] locateDelimiters(byte[] msgInBytes) {
int[] delimiters = new int[NUMBER_OF_PARAMS_IN_SECURE_QR_CODE + 1];
int index = 0;
int delimiterIndex;
for (int i = 0; i <= NUMBER_OF_PARAMS_IN_SECURE_QR_CODE; i++) {
delimiterIndex = getNextDelimiterIndex(msgInBytes, index);
delimiters[i] = delimiterIndex;
index = delimiterIndex + 1;
}
return delimiters;
}
private static String getValueInRange(byte[] msgInBytes, int start, int end) {
return new String(Arrays.copyOfRange(msgInBytes, start, end), Charset.forName("ISO-8859-1"));
}
private static int getNextDelimiterIndex(byte[] msgInBytes, int index) {
int i = index;
for (; i < msgInBytes.length; i++) {
if (msgInBytes[i] == -1) {
break;
}
}
return i;
}
private static byte[] decompressByteArray(byte[] bytes) throws IOException {
java.io.ByteArrayInputStream bytein = new ByteArrayInputStream(bytes);
java.util.zip.GZIPInputStream gzin = new GZIPInputStream(bytein);
java.io.ByteArrayOutputStream byteout = new ByteArrayOutputStream();
int res = 0;
byte buf[] = new byte[1024];
while (res >= 0) {
res = gzin.read(buf, 0, buf.length);
if (res > 0) {
byteout.write(buf, 0, res);
}
}
return byteout.toByteArray();
}
private String formatDate(String rawDateString, String[] possibleFormats) {
if (rawDateString.equals("")) {
return "";
}
SimpleDateFormat toFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
ParseException parseException = null;
for (String fromFormatPattern : possibleFormats) {
try {
SimpleDateFormat fromFormat = new SimpleDateFormat(fromFormatPattern);
date = fromFormat.parse(rawDateString);
break;
} catch (ParseException e) {
parseException = e;
}
}
if (date != null) {
return toFormat.format(date);
} else if (parseException != null) {
System.err.println("Expected dob to be in dd/mm/yyyy or yyyy-mm-dd format, got " + rawDateString);
return rawDateString;
} else {
throw new AssertionError("This code is unreachable");
}
}
#NonNull
protected String formatGender(String gender) throws ParseException {
String lowercaseGender = gender.toLowerCase();
if (lowercaseGender.equals("male") || lowercaseGender.equals("m")) {
return "M";
} else if (lowercaseGender.equals("female") || lowercaseGender.equals("f")) {
return "F";
} else if (lowercaseGender.equals("other") || lowercaseGender.equals("o")) {
return "O";
} else {
throw new ParseException("404 gender not found", 0);
}
}
#NonNull
private String getStatusText(int statusCode) {
switch (statusCode) {
case ScanResult.STATUS_SUCCESS:
return "✓";
default:
return "✗";
}
}
#NonNull
private String getDobGuess(String dob, String yob) {
if (dob.equals("")) {
Integer yearInt;
try {
yearInt = Integer.parseInt(yob);
} catch (NumberFormatException e) {
return "";
}
// June 1 of the year
return Integer.toString(yearInt) + "-06-01";
} else {
return dob;
}
}
Github Code Link
Just now got the solution, fetched exact mobile and email hash value from byte array
first remove last 256 bytes from byte array then,
if only mobile present then take last 32 bytes from byte array for mobile
i.e. (array.length - 32 to array.length)
else if only email present then take last 32 bytes from byte array for email i.e. (array.length - 32 to array.length)
else if both email and mobile present then take last 32 bytes from byte array for mobile, take next last 32 bytes for email
i.e. (mobile = array.length - 32 to array.length and
email = array.length - 64 to array.length - 32)
From the byte array you need to read values from index byte_array_length - 256 - 32 to byte_array_length - 256 to get the mobile hash in bytes(you can easily convert the bytes to hexadecimal string) and similarly for email you need to read from index byte_array_length - 256 - 32 - 32 to byte_array_length - 256 - 32.
I have implemented a library for decoding the same but the implementation is in Python.
The question is a bit old but future readers might find these resources useful.
PyPI: aadhaar-py
Github: https://github.com/vishaltanwar96/aadhaar-py

My array Printing NULL

In the method, i have all these initialize
Scanner input = new Scanner(System.in);
File file = new File("order.dat");
File viewOrder = new File("ViewOrder.dat");
String orderNo, itemNo, itemNameHolder, qtyHolder, priceHolder, status;
int hold, count = 0, countArray = 0;
double tempPriceHolder, totalPrice = 0;
String tempStatus = "";
String[] holdItemNo = null;
String[] holdName = null;
Integer[] holdQty = null;
Double[] holdTotal = null;
String[] holdStatus = null;
After, i try to read all my content in the file and store the content into holdX array
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = null;
while ((line = br.readLine()) != null) {
String tokens[] = line.split(";");
orderNo = tokens[0];
itemNo = tokens[1];
itemNameHolder = tokens[2];
qtyHolder = tokens[3];
priceHolder = tokens[4];
status = tokens[5];
if (orderNo.equalsIgnoreCase(userOrderNo)) {
tempPriceHolder = Double.parseDouble(priceHolder);
hold = Integer.parseInt(qtyHolder);
tempPriceHolder = tempPriceHolder * hold;
totalPrice += tempPriceHolder;
countArray++;
holdItemNo = new String[countArray];
holdName = new String[countArray];
holdQty = new Integer[countArray];
holdTotal = new Double[countArray];
holdStatus = new String[countArray];
if (status.matches("s")) {
tempStatus = "Success";
} else if (status.matches("p")) {
tempStatus = "Partially Full";
} else if (status.matches("o")) {
tempStatus = "Out of Stock";
}
holdItemNo[count] = itemNo;
holdName[count] = itemNameHolder;
holdQty[count] = hold;
holdTotal[count] = tempPriceHolder;
holdStatus[count] = tempStatus;
count++;
}
}
} catch (Exception e) {
System.out.println("Error");
}
Final, i write all my array into a new file.
System.out.printf("%s %15s %15s %10s %10s\n", "Item No", "Description", "Quantity", "Total", "Status");
for (int i = 0; i < holdItemNo.length; i++) {
System.out.printf("\n%-11s %-18s %-13s $%-8s %s \n", holdItemNo[i], holdName[i], holdQty[i], holdTotal[i], holdStatus[i]);
}
System.out.println("-----------------------------------------------------------------------");
System.out.printf("%46s %s\n", "$", totalPrice);
System.out.print("Print Order to file Y/N: ");
String choice = input.next();
if (choice.equalsIgnoreCase("y")) {
try {
PrintWriter bw = new PrintWriter(new FileWriter("ViewOrder.dat", true));
for (int i = 0; i < holdItemNo.length; i++) {
bw.write(userOrderNo + ";" + holdItemNo[i] + ";" + holdName[i] + ";" + holdQty[i] + ";" + holdTotal[i] + ";" + holdStatus[i] + "\n");
bw.flush();
}
bw.flush();
bw.close();
System.out.println("Sucessfull!");
} catch (Exception e) {
System.out.println("Error");
}
} else if (choice.equalsIgnoreCase("n")) {
System.out.println("");
}
but the problem is even my code is working but the output is not what i expected. It printed out the printed out the last content and also the sub price is working as well but the rest is only printed out NULL.
Example
Also, it gave me warning of Derefencing possible null pointer on the array.length
for (int i = 0; i < holdItemNo.length; i++) {
bw.write(userOrderNo + ";" + holdItemNo[i] + ";" + holdName[i] + ";" + holdQty[i] + ";" + holdTotal[i] + ";" + holdStatus[i] + "\n");
bw.flush();
}
Guessing:
holdItemNo = new String[countArray];
and the following lines: you are creating these new array objects within your reading loop (inside a condition).
So probably that condition never goes true; therefore your arrays stay all null. But even when the condition is met - you probably expect that to happen more then once. And guess what: you are creating completely new arrays then. While throwing away the previously created array. Each time the if condition turns true you will lose previously stored values!
So the answer is: create your arrays before entering the loop. This means that you either have to query "how many slots to create" upfront; or you have to create an array with say 100 empty slots; and within your loop you then have to check if you still have free slots.
Or you start using java.util.List resp. ArrayList - which allows for dynamic adding of elements.

Storing a single csv object into an array

hey ive got a chunk of code thats supposed loads lines of csv file into an array of objects:
public static WarehouseItem[] loadRecords(WarehouseItem[] records) {
FileInputStream fileStrm = null;
InputStreamReader rdr;
BufferedReader bufRdr;
int numRows = 0;
String warehouseItem;
String filename;
filename = ConsoleInput.readLine("Please enter the filename (DataMillion.csv OR DataThousand.csv)");
try {
fileStrm = new FileInputStream(filename);
rdr = new InputStreamReader(fileStrm);
bufRdr = new BufferedReader(rdr);
warehouseItem = bufRdr.readLine();
records[numRows] = new WarehouseItem(warehouseItem); //NULL POINTER EXCEPTION HERE
System.out.println(records[0].toString(records[0].columnVals));
while (warehouseItem != null) {
numRows++;
records[numRows] = new WarehouseItem(warehouseItem);
warehouseItem = bufRdr.readLine();
}
fileStrm.close();
}
catch (IOException e) {
if (fileStrm != null) {
try {
fileStrm.close();
} catch (IOException ex2) {}
}
System.out.println("Error in file processing: " + e.getMessage());
}
main(null);
return records;
}
but when i run it, i get a NullPointerException on the line
records[numRows] = new WarehouseItem(warehouseItem);
is there anything that i missed??
heres the WarehouseItem constructor + toString:
public class WarehouseItem {
String[] columnVals;
int numColumns = 5;
public WarehouseItem(String warehouseItem) {
String key, brand, model, price, weightInKG;
int intWeightInKG;
double doublePrice;
StringTokenizer strTok;
strTok = new StringTokenizer(warehouseItem, ",");
key = strTok.nextToken();
brand = strTok.nextToken();
model = strTok.nextToken();
intWeightInKG = Integer.parseInt(strTok.nextToken());
doublePrice = Double.valueOf(strTok.nextToken());
weightInKG = String.valueOf(intWeightInKG);
price = String.valueOf(doublePrice);
String[] columnVals = {key, brand, model, weightInKG, price};
if(columnVals.length != 5)
throw new IllegalStateException("Invalid CSV: not enough columns");
}
public String toString(String[] columnVals) {
return ("Key: " + columnVals[0] + "\n" +
"Brand: " + columnVals[1] + "\n" +
"Model: " + columnVals[2] + "\n" +
"Weight: " + columnVals[3] + "\n" + " kg" +
"Price: " + "$" + columnVals[4] + "\n");
}
}
What my problem is the values aren't getting stored into the array records properly and im not sure why
You didn't initialize array, that was a cause NullPointerException in your code, but if you can't use array don't use it.
The number of lines might exceed the capacity of array, use List instead
List<WarehouseItem> records = new ArrayList<>();
String line = bufRdr.readLine();
while (line != null) {
WarehauseItem warehauseItem = new WarehauseItem();
records.add(warehauseItem);
warehauseItem.processLine(line);
line = bufRdr.readLine();
}
numRows = records.size();
When you create an array of objects in Java, it is initialized with all nulls. That is why you get a nullpointerexception.
So you need to create an object for each array position. In fact instead of calling a method you could just make that method a constructor; that would be simpler.
I also noticed another mistake: the method sets local variables, which only exist for the lifetime of the method, when in fact it should set instance variables.
Then I noticed a third mistake: You just caught exception, and assumed that that indicated missing columns; in fact it could indicate invalidly-typed data inside a column (e.g. string instead of integer).
You missed object creation records[numRows]=new WarehouseItem();
Your code need to be like this.
while (warehouseItem != null) {
records[numRows]=new WarehouseItem(); //here you forgot the object creation.
warehouseItem = bufRdr.readLine();
records[numRows].processLine(warehouseItem);
numRows++;
}
Because you haven't assigned anything to records[numRows]. You only defined records as an array of WarehouseItem objects.
You should assign a new WarehouseItem to that index of the array before you can use.
records[numRows] = new WarehouseItem();
warehouseItem = bufRdr.readLine();
records[numRows].processLine(wareHouseitem);

Example using WikipediaTokenizer in Lucene

I want to use WikipediaTokenizer in lucene project - http://lucene.apache.org/java/3_0_2/api/contrib-wikipedia/org/apache/lucene/wikipedia/analysis/WikipediaTokenizer.html But I never used lucene. I just want to convert a wikipedia string into a list of tokens. But, I see that there are only four methods available in this class, end, incrementToken, reset, reset(reader). Can someone point me to an example to use it.
Thank you.
In Lucene 3.0, next() method is removed. Now you should use incrementToken to iterate through the tokens and it returns false when you reach the end of the input stream. To obtain the each token, you should use the methods of the AttributeSource class. Depending on the attributes that you want to obtain (term, type, payload etc), you need to add the class type of the corresponding attribute to your tokenizer using addAttribute method.
Following partial code sample is from the test class of the WikipediaTokenizer which you can find if you download the source code of the Lucene.
...
WikipediaTokenizer tf = new WikipediaTokenizer(new StringReader(test));
int count = 0;
int numItalics = 0;
int numBoldItalics = 0;
int numCategory = 0;
int numCitation = 0;
TermAttribute termAtt = tf.addAttribute(TermAttribute.class);
TypeAttribute typeAtt = tf.addAttribute(TypeAttribute.class);
while (tf.incrementToken()) {
String tokText = termAtt.term();
//System.out.println("Text: " + tokText + " Type: " + token.type());
String expectedType = (String) tcm.get(tokText);
assertTrue("expectedType is null and it shouldn't be for: " + tf.toString(), expectedType != null);
assertTrue(typeAtt.type() + " is not equal to " + expectedType + " for " + tf.toString(), typeAtt.type().equals(expectedType) == true);
count++;
if (typeAtt.type().equals(WikipediaTokenizer.ITALICS) == true){
numItalics++;
} else if (typeAtt.type().equals(WikipediaTokenizer.BOLD_ITALICS) == true){
numBoldItalics++;
} else if (typeAtt.type().equals(WikipediaTokenizer.CATEGORY) == true){
numCategory++;
}
else if (typeAtt.type().equals(WikipediaTokenizer.CITATION) == true){
numCitation++;
}
}
...
WikipediaTokenizer tf = new WikipediaTokenizer(new StringReader(test));
Token token = new Token();
token = tf.next(token);
http://www.javadocexamples.com/java_source/org/apache/lucene/wikipedia/analysis/WikipediaTokenizerTest.java.html
Regards
public class WikipediaTokenizerTest {
static Logger logger = Logger.getLogger(WikipediaTokenizerTest.class);
protected static final String LINK_PHRASES = "click [[link here again]] click [http://lucene.apache.org here again] [[Category:a b c d]]";
public WikipediaTokenizer testSimple() throws Exception {
String text = "This is a [[Category:foo]]";
return new WikipediaTokenizer(new StringReader(text));
}
public static void main(String[] args){
WikipediaTokenizerTest wtt = new WikipediaTokenizerTest();
try {
WikipediaTokenizer x = wtt.testSimple();
logger.info(x.hasAttributes());
Token token = new Token();
int count = 0;
int numItalics = 0;
int numBoldItalics = 0;
int numCategory = 0;
int numCitation = 0;
while (x.incrementToken() == true) {
logger.info("seen something");
}
} catch(Exception e){
logger.error("Exception while tokenizing Wiki Text: " + e.getMessage());
}
}

Categories