|
| 1 | +package Annotation; |
| 2 | + |
| 3 | +import java.sql.PreparedStatement; |
| 4 | +import java.sql.ResultSet; |
| 5 | +import java.sql.SQLException; |
| 6 | +import java.sql.Statement; |
| 7 | +import java.text.DateFormat; |
| 8 | +import java.text.SimpleDateFormat; |
| 9 | +import java.util.Date; |
| 10 | +import java.util.LinkedList; |
| 11 | + |
| 12 | +import DataBase.DataBaseAnnotationSaver; |
| 13 | +import Main.MarvinSemAnnotator; |
| 14 | +import Main.Word; |
| 15 | +import Main.WordMeaningOutputElement; |
| 16 | + |
| 17 | + |
| 18 | +public class MetaMapAnnotatorMain { |
| 19 | + |
| 20 | + public static void main(String[] args) { |
| 21 | + // TODO Auto-generated method stub |
| 22 | + DataBaseAnnotationSaver dbas = new DataBaseAnnotationSaver(); |
| 23 | + try { |
| 24 | + Statement stmt = dbas.conn.createStatement(); |
| 25 | + String insertTableSQL = "SELECT * FROM Cell where idCell > 489245"; // change this to be idCell that was available before running the last TableAnnotator load. Currently 489245. |
| 26 | + ResultSet rs = stmt.executeQuery(insertTableSQL); |
| 27 | + MarvinSemAnnotator marvin = new MarvinSemAnnotator(); |
| 28 | + while (rs.next()) { |
| 29 | + int idCell = rs.getInt("idCell"); |
| 30 | + String CellID = rs.getString("CellID"); |
| 31 | + String CellType = rs.getString("CellType"); |
| 32 | + int Table_idTable = rs.getInt("Table_idTable"); |
| 33 | + int RowN = rs.getInt("RowN"); |
| 34 | + int ColumnN = rs.getInt("ColumnN"); |
| 35 | + String Content = rs.getString("Content"); |
| 36 | + System.out.println("Processing cell record - \n\tidCell: " + idCell + "\n\tCellID: " + CellID + "\n\tCellType: " + CellType + "\n\tTable_idTable: " + Table_idTable + "\n\tRowN: " + RowN + "\n\tColumnN: " + ColumnN); |
| 37 | + System.out.println("Cell content:" + Content); |
| 38 | + if(Content==null) |
| 39 | + { |
| 40 | + Content = ""; |
| 41 | + } |
| 42 | + int mathTypeIndex = Content.indexOf("MathType@"); |
| 43 | + if(mathTypeIndex>0) |
| 44 | + { |
| 45 | + Content = Content.substring(0, mathTypeIndex); |
| 46 | + } |
| 47 | + LinkedList<Word> words = null; |
| 48 | + if(Content!=null){ |
| 49 | + Content = Content.trim(); |
| 50 | + words = marvin.annotate(Content); |
| 51 | + if(words == null){ |
| 52 | + System.out.println("ERROR: Marvin returned NULL when annotating content (see above) - this cell will be skipped for now "); |
| 53 | + System.out.println("ERROR: letting process rest and then initiating a new marvin metamap annotation connection...."); |
| 54 | + try { |
| 55 | + Thread.sleep(1000); //1000 milliseconds is one second. |
| 56 | + } catch(InterruptedException ex) { |
| 57 | + Thread.currentThread().interrupt(); |
| 58 | + } |
| 59 | + marvin = new MarvinSemAnnotator(); |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + for(Word w:words) |
| 64 | + { |
| 65 | + |
| 66 | + for(WordMeaningOutputElement wm: w.wordmeanings) |
| 67 | + { |
| 68 | + System.out.println(wm.AgentName); |
| 69 | + Statement stmt8 = dbas.conn.createStatement(); |
| 70 | + String insertTableSQL8 = "INSERT INTO Annotation (Content,Start,End,AnnotationID,AgentType,AgentName,AnnotationURL,EnvironmentDescription,Cell_idCell,AnnotationDescription,AnnotationSchemaVersion,DateOfAction, Location) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
| 71 | + PreparedStatement preparedStatement8 = dbas.conn.prepareStatement(insertTableSQL8,Statement.RETURN_GENERATED_KEYS); |
| 72 | + preparedStatement8.setString(1,wm.appearingWord); |
| 73 | + preparedStatement8.setInt(2,wm.startAt); |
| 74 | + preparedStatement8.setInt(3,wm.endAt); |
| 75 | + preparedStatement8.setString(4,wm.id); |
| 76 | + preparedStatement8.setString(5,"Software"); |
| 77 | + preparedStatement8.setString(6,wm.AgentName); |
| 78 | + preparedStatement8.setString(7,wm.URL); |
| 79 | + preparedStatement8.setString(8,wm.EnvironmentDesc); |
| 80 | + preparedStatement8.setInt(9,idCell); |
| 81 | + preparedStatement8.setString(10,wm.Description); |
| 82 | + preparedStatement8.setString(11,wm.AgentVersion);// Should be version |
| 83 | + //DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); |
| 84 | + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| 85 | + Date date = new Date(); |
| 86 | + preparedStatement8.setString(12,dateFormat.format(date)); |
| 87 | + preparedStatement8.setString(13,wm.Location); // Should be location |
| 88 | + // execute insert SQL stetement |
| 89 | + preparedStatement8.executeUpdate(); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + dbas.CloseDBConnection(); |
| 96 | + |
| 97 | + } catch (SQLException e) { |
| 98 | + // TODO Auto-generated catch block |
| 99 | + e.printStackTrace(); |
| 100 | + } |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | +} |
0 commit comments