How does a parser (for example, HTML) work?

Tokenizing can be composed of a few steps, for example, if you have this html code: <html> <head> <title>My HTML Page</title> </head> <body> <p style=”special”> This paragraph has special style </p> <p> This paragraph is not special </p> </body> </html> the tokenizer may convert that string to a flat list of significant tokens, discarding whitespaces … Read more

How do I read input character-by-character in Java?

Use Reader.read(). A return value of -1 means end of stream; else, cast to char. This code reads character data from a list of file arguments: public class CharacterHandler { //Java 7 source level public static void main(String[] args) throws IOException { // replace this with a known encoding if possible Charset encoding = Charset.defaultCharset(); … Read more

Tokenizing Error: java.util.regex.PatternSyntaxException, dangling metacharacter ‘*’

No, the problem is that * is a reserved character in regexes, so you need to escape it. String [] separado = line.split(“\\*”); * means “zero or more of the previous expression” (see the Pattern Javadocs), and you weren’t giving it any previous expression, making your split expression illegal. This is why the error was … Read more

How do I tokenize a string sentence in NLTK?

This is actually on the main page of nltk.org: >>> import nltk >>> sentence = “””At eight o’clock on Thursday morning … Arthur didn’t feel very good.””” >>> tokens = nltk.word_tokenize(sentence) >>> tokens [‘At’, ‘eight’, “o’clock”, ‘on’, ‘Thursday’, ‘morning’, ‘Arthur’, ‘did’, “n’t”, ‘feel’, ‘very’, ‘good’, ‘.’]

Google Sites API full-text search does not work for non-Western languages

I know how it feels when waiting for somebodies support to handle an API bug while your application is going to not met deadlines defined. The issue you described really sound like a bug, so for “clean” solution you will have to wait until Google Sites team guys will resolve this bug (I already upvoted … Read more

How to get a Token from a Lucene TokenStream?

Yeah, it’s a little convoluted (compared to the good ol’ way), but this should do it: TokenStream tokenStream = analyzer.tokenStream(fieldName, reader); OffsetAttribute offsetAttribute = tokenStream.getAttribute(OffsetAttribute.class); TermAttribute termAttribute = tokenStream.getAttribute(TermAttribute.class); while (tokenStream.incrementToken()) { int startOffset = offsetAttribute.startOffset(); int endOffset = offsetAttribute.endOffset(); String term = termAttribute.term(); } Edit: The new way According to Donotello, TermAttribute has been … Read more