Novidades‎ > ‎TLanguage‎ > ‎

Exemplos

Definições Úteis    


Código

 Descrição

${Y} ${X} ${Z} := X
@ maxVarDomainSize 1 Y
@ maxVarDomainSize 1 Z
@ minVarDomainSize 1 Y
@ maxVarDomainSize 1 X
@ X is list
@ X[begin end] pattern [A-Z].*;  
Lista palavras que iniciam com letra maiúscula no final e no meio de uma sentença. É uma heurística para nomes próprios.

Utilizando a API via Código

Implementa uma heurística para extrair nomes próprios de um texto. A heurística supõe que nomes próprios são nomes que iniciam com letra maiúscula que não estão no início de uma sentença.

Caixa de texto

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

import tl.core.TLIInterpreter;
import tl.core.TokenList;
import tl.interpreter.DefaultContentSource;
import tl.utlis.TextUtils;


public class ExtractNouns {
public static void main(String args[]) throws Exception {
String target = "input";
String content = new DefaultContentSource().getContent(target);
TLIInterpreter inter = new TLIInterpreter(new FileReader("definitions"));
List<String> test = loadTest();
HashMap<String, String> repeated = new HashMap<String, String>();
int q = 0;
while (TextUtils.hasNextTokenList(content)) {
TokenList tl = TextUtils.readNextTokenList(content, target, inter.getState());
HashMap<String, Object> resp = new HashMap<String, Object>();
inter.start();
while (inter.parse(tl, resp)) {
Object xvalue = resp.get("X");
@SuppressWarnings("unchecked")
List<String> values = (List<String>) xvalue;
if (values != null) {
String word = getWord(values);
if (!repeated.containsKey(word) && test.contains(word)) {
repeated.put(word, word);
System.out.println("ACERTOU: " + word);
q++;
}
}
resp.clear();
}
inter.end();
}

System.out.println("ACETOU " + q + " PALAVRAS");
}

public static String getWord(List<String> list) {
StringBuilder sb = new StringBuilder();
for (String w : list) {
sb.append(w + " ");
}
return sb.toString().trim();
}
public static List<String> loadTest() throws IOException {
LinkedList<String> test = new LinkedList<String>();
Scanner scan = new Scanner(new File("test"));
while (scan.hasNextLine()) {
test.add(scan.nextLine());
}
return test;
}
}


Baixar Projeto do Eclipse
Č
ċ
ď
Gilzamir Ferreira Gomes,
13/08/2011 20:42