public static <T extends Lexeme, L extends Lexicon<T>> L readFrom(final Class<L> lexiconClass, final Class<T> lexemeClass, final Reader reader) throws IOException { final List<T> lexemes = Lists.newArrayList(); final BufferedReader in = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); String line; while ((line = in.readLine()) != null) { T token = Lexeme.parse(lexemeClass, line); if (token == null) { continue; } lexemes.add(token); } return create(lexiconClass, lexemes); }
public Set<T> match(final KAFDocument document, final Term term) { return ImmutableSet.copyOf(match(document, ImmutableSet.of(term)).get(term)); }
public static synchronized SenticNet getInstance() { if (instance == null) { final String location = Objects.firstNonNull( Environment.getProperty("senticnet.home"), "SenticNet.tsv"); try { instance = Lexicon.readFrom(SenticNet.class, Lexeme.class, location); } catch (final Throwable ex) { throw new Error("Could not read default subjectivity lexicon at " + location, ex); } } return instance; }
public void writeTo(final String location) throws IOException { try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(location)))) { writeTo(writer); } }
public static synchronized SubjectivityLexicon getInstance() { if (instance == null) { final String location = Objects.firstNonNull( Environment.getProperty("subjectivity.lexicon.home"), "SubjectivityLexicon.tsv"); try { instance = Lexicon.readFrom(SubjectivityLexicon.class, Lexeme.class, location); } catch (final Throwable ex) { throw new Error("Could not read default subjectivity lexicon at " + location, ex); } } return instance; }
public static synchronized Intensities getInstance() { if (instance == null) { final String location = Objects.firstNonNull( Environment.getProperty("intensities.home"), "intensities.tsv"); try { instance = Lexicon.readFrom(Intensities.class, Lexeme.class, location); } catch (final Throwable ex) { throw new Error("Could not read default intensity lexicon at " + location, ex); } } return instance; }
public static <T extends Lexeme, L extends Lexicon<T>> L readFrom(final Class<L> lexiconClass, final Class<T> lexemeClass, final String location) throws IOException { // Try to open a file at the location specified, falling back to search on the classpath Reader reader = null; try { reader = IO.utf8Reader(IO.buffer(IO.read(location))); } catch (final Throwable ex) { final URL url = lexiconClass.getResource(location); if (url == null) { Throwables.propagateIfPossible(ex, IOException.class); Throwables.propagate(ex); } reader = IO.utf8Reader(url.openStream()); } // Read the lexicon from the opened reader try { return readFrom(lexiconClass, lexemeClass, reader); } finally { reader.close(); } }