/** * Close all open index handles. */ public void cleanup() { try { if (iw != null) iw.close(); if (ir != null) ir.close(); if (directory != null) directory.close(); } catch (IOException ioe) { fireEventOccurred(new DataFileErrorEvent(ioe.getMessage(), "[LuceneEnv - cleanup]")); } }
/** * Constructor for a customized message with extension. * * @param message * String * @param extension * String */ public DataFileErrorEvent(String message, String extension) { super(message, extension); super.desc = "An error occurred with one or more data files."; this.setLog4jLevel(Level.ERROR); }
/** * Constructor which initialises an empty LuceneEnv. * * @param indexdir * String * @param create * boolean */ public LuceneEnv(String indexdir, boolean create) { this.indexdir = indexdir; this.create = create; if (create) new File(indexdir).mkdirs(); try { // open a Directory for the index directory = FSDirectory.open ( new File ( indexdir ).toPath () ); } catch (IOException ioe) { fireEventOccurred(new DataFileErrorEvent(ioe.getMessage(), "[LuceneEnv - constructor]")); } }
/** * Adds an interacting factor to current list. * * @param interactingFactor - String */ protected void addInteractingFactor(String interactingFactor) { if (DEBUG && interactingFactors.contains(interactingFactor)) { Parser.propagateEventOccurred(new DataFileErrorEvent( "InteractionFactor id already exists: " +interactingFactor+" in "+getAccession(), "")); } this.interactingFactors.add(interactingFactor); }
/** * Adds a matrix to current list. * * @param matrix - String */ protected void addMatrix(String matrix) { if (DEBUG && matrices.contains(matrix)) { Parser.propagateEventOccurred(new DataFileErrorEvent( "Matrix id already exists: " +matrix+" in "+getAccession(), "")); } this.matrices.add(matrix); }
/** * Adds sets of used meta data to the index. */ private void addMetadataToIndex() { // new document for fields Document doc = new Document(); doc.add(new Field(LASTDOCUMENT, "true", StringField.TYPE_NOT_STORED )); // Attribute fields about the last document were initially not stored. However, this is not good for Lucene 6, // because it complaints that a field name having both docs where it is stored and not stored cannot be used to // build certain searches (https://goo.gl/Ee1sfm) // for (String name : listOfConceptAttrNames) doc.add(new Field(CONATTRIBUTE_FIELD + DELIM + name, name, FIELD_TYPE_STORED_INDEXED_VECT_STORE )); for (String name : listOfRelationAttrNames) doc.add(new Field(RELATTRIBUTE_FIELD + DELIM + name, name, FIELD_TYPE_STORED_INDEXED_VECT_STORE )); for (String elementOf : listOfConceptAccDataSources) doc.add(new Field(CONACC_FIELD + DELIM + elementOf, elementOf, StoredField.TYPE )); // add last document try { iw.addDocument(doc); } catch (CorruptIndexException cie) { fireEventOccurred(new DataFileErrorEvent(cie.getMessage(), "[LuceneEnv - addMetadataToIndex]")); } catch (IOException ioe) { fireEventOccurred(new DataFileErrorEvent(ioe.getMessage(), "[LuceneEnv - addMetadataToIndex]")); } }
/** * Adds a publication to current list. * * @param publication - Publication */ public void addPublication(Publication publication) { if (DEBUG && publications.contains(publication)) { Parser.propagateEventOccurred(new DataFileErrorEvent( "Publication id already exists: " +publication.getPmid()+" in "+getAccession(), "addPublication(Publication publication)")); } publications.add(publication); }
protected void makeFactorInteraction() { Iterator<String> keys = factorInteraction.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); ONDEXConcept from = factorsWritten.get(key); ONDEXConcept to = factorsWritten.get(factorInteraction.get(key)); if (to != null) { aog.getFactory().createRelation(from, to, it_wi, evi); } else { Parser.propagateEventOccurred(new DataFileErrorEvent( "Factor for interaction missing: from " + from.getPID() + " to " + factorInteraction.get(from) + " (missing).", "makeFactorInteraction()")); } } }
reader = null; } catch (FileNotFoundException fnfe) { Parser.propagateEventOccurred(new DataFileErrorEvent(fnfe .getMessage(), "")); } catch (IOException ioe) { Parser.propagateEventOccurred(new DataFileErrorEvent(ioe .getMessage(), ""));
} catch (IOException ioe) { Parser.propagateEventOccurred( new DataFileErrorEvent(ioe.getMessage(), "AbstractTPParser(ConceptWriter conceptWriter, ParserArguments pa)"));
/** * Close a potentially open index. */ public void closeIndex() { try { // check if index open for writing if ( !indexWriterIsOpen ) return; // add last document to index addMetadataToIndex (); iw.prepareCommit (); iw.commit (); iw.close (); indexWriterIsOpen = false; } catch (CorruptIndexException cie) { fireEventOccurred ( new DataFileErrorEvent ( cie.getMessage(), "[LucenceEnv - closeIndex]" ) ); } catch (IOException ioe) { fireEventOccurred ( new DataFileErrorEvent ( ioe.getMessage(), "[LucenceEnv - closeIndex]" ) ); } }
String tfAccession = tfIt.next(); Parser .propagateEventOccurred(new DataFileErrorEvent( "TF Accession: " + tfAccession
fireEventOccurred ( new DataFileErrorEvent ( ioe.getMessage (), "[LuceneEnv - searchTopConcepts]" ) );
fireEventOccurred ( new DataFileErrorEvent ( ioe.getMessage (), "[LuceneEnv - searchInConcepts]" ) );
/** * Open index for writing. */ public void openIndex () { // open index modifier to write to index try { if ( indexWriterIsOpen ) closeIndex (); ir.close (); IndexWriterConfig writerConfig = new IndexWriterConfig ( DEFAULTANALYZER ); writerConfig.setOpenMode ( OpenMode.CREATE_OR_APPEND ); // set RAM buffer, hopefully speeds up things writerConfig.setRAMBufferSizeMB ( getOptimalRamBufferSize () ); iw = new IndexWriter ( directory, writerConfig ); indexWriterIsOpen = true; // deletes the last record that has attribute names, // that will have to be rebuilt iw.deleteDocuments ( new Term ( LASTDOCUMENT, "true" ) ); System.out.println ( "Lucene Metadata delete: " + iw.hasDeletions () ); iw.commit (); } catch ( IOException ioe ) { fireEventOccurred ( new DataFileErrorEvent ( ioe.getMessage (), "[LucenceEnv - openIndex]" ) ); } }
/** * Returns the number of Relations that contain this word. * * @param an * the Attribute attribute to search within * @param word * the word/term to search for * @return int */ public int getFrequenceyOfWordInRelationAttribute(AttributeName an, String word) { String fieldname = RELATTRIBUTE_FIELD + DELIM + an.getId(); Term term = new Term(fieldname, word); try { // Returns the number of documents containing the term. this.ensureReaderAndSearcherOpen (); return ir.docFreq ( term ); } catch (IOException e) { fireEventOccurred(new DataFileErrorEvent(e.getMessage(), "[LuceneEnv - getFrequenceyOfWordInRelationAttribute]")); } return 0; }
/** * Typical usage get the number of Publications (Concept) with Abstracts * (Attribute) that contain the word "regulates". Return the number of * Concepts that contain this word. * * @param an * the Attribute attribute to search within * @param word * the word/term to search for * @return int */ public int getFrequenceyOfWordInConceptAttribute(AttributeName an, String word) { String fieldname = CONATTRIBUTE_FIELD + DELIM + an.getId(); Term term = new Term(fieldname, word); try { this.ensureReaderAndSearcherOpen (); return ir.docFreq( term ); } catch (IOException e) { fireEventOccurred(new DataFileErrorEvent(e.getMessage(), "[LuceneEnv - getFrequenceyOfWordInConceptAttribute]")); } return 0; }
/** * Returns the number of Relations that contain these words. * * @param an * the Attribute attribute to search within * @param word * the word/term to search for * @return int[] */ public int[] getFrequenceyOfWordInRelationAttribute(AttributeName an, String[] word) { String fieldname = RELATTRIBUTE_FIELD + DELIM + an.getId(); try { this.ensureReaderAndSearcherOpen (); int[] freqs = new int[word.length]; for (int i = 0; i < word.length; i++) { freqs[i] = ir.docFreq ( new Term(fieldname, word[i]) ); } // Returns the number of documents containing the terms. return freqs; } catch (IOException e) { fireEventOccurred(new DataFileErrorEvent(e.getMessage(), "[LuceneEnv - getFrequenceyOfWordInRelationAttribute]")); } return new int[0]; }
fireEventOccurred ( new DataFileErrorEvent ( ex.getMessage (), "[LuceneEnv - addRelationToIndex]" ) );
/** * Faster method than getFrequenceyOfWordInConceptAttribute(AttributeName * an, String word) as calls to IO are less (-: Typical usage get the number * of Publications (Concept) with Abstracts (Attribute) that contain the * word "regulates". Returns the number of Concepts that contain this word. * * @param an * the Attribute attribute to search within * @param word * the word/term to search for * @return int[] */ public int[] getFrequenceyOfWordInConceptAttribute(AttributeName an, String[] word) { String fieldname = CONATTRIBUTE_FIELD + DELIM + an.getId(); try { this.ensureReaderAndSearcherOpen (); int[] freqs = new int[word.length]; for (int i = 0; i < word.length; i++) { freqs[i] = ir.docFreq ( new Term ( fieldname, word[i] ) ); } // Returns the number of documents containing the terms. return freqs; } catch (IOException e) { fireEventOccurred(new DataFileErrorEvent(e.getMessage(), "[LuceneEnv - getFrequenceyOfWordInConceptAttribute]")); } return new int[0]; }