Search in sources :

Example 11 with TableTuple

use of main.database.TableTuple in project Info-Evaluation by TechnionYP5777.

the class AnalyzeParagraphTest method test14.

@Test
public void test14() {
    final Sentence sent = new Sentence("Mark Salling was arrested for felony possession of child pornography on Dec 29. His representative had no comment on the matter.");
    final TableTuple tt = new AnalyzeParagragh(sent, "2015").Analyze();
    assertEquals("12/29/2015", tt.getDate());
    System.out.println((tt.getRegularDate() + ""));
}
Also used : TableTuple(main.database.TableTuple) AnalyzeParagragh(main.Analyze.AnalyzeParagragh) Sentence(edu.stanford.nlp.simple.Sentence) Test(org.junit.Test)

Example 12 with TableTuple

use of main.database.TableTuple in project Info-Evaluation by TechnionYP5777.

the class AnalyzeSourcesTest method checkMerge.

@Test
public void checkMerge() {
    final AnalyzeSources as = new AnalyzeSources();
    as.addSource(src1);
    as.addSource(src2, "2015");
    for (TableTuple ¢ : as.getData()) {
        if ("Mark Salling".equals(¢.getName())) {
            assert "12/29/2015".equals(¢.getDate());
            assert "Tue Dec 29 00:00:00 IST 2015".equals((¢.getRegularDate() + ""));
        }
        if ("Dustin Diamond".equals(¢.getName()))
            assert "12/26/2016".equals(¢.getDate());
    }
}
Also used : TableTuple(main.database.TableTuple) AnalyzeSources(main.Analyze.AnalyzeSources) Test(org.junit.Test)

Example 13 with TableTuple

use of main.database.TableTuple in project Info-Evaluation by TechnionYP5777.

the class AnalyzeSourcesTest method testPrint.

@Test
public void testPrint() {
    final AnalyzeSources as = new AnalyzeSources();
    as.addSource(src1);
    as.addSource(src2);
    // as.getData().printList();
    for (TableTuple tt : as.getData()) {
        for (String ¢ : tt.getKeyWords()) System.out.println(¢);
        System.out.println();
    }
}
Also used : TableTuple(main.database.TableTuple) AnalyzeSources(main.Analyze.AnalyzeSources) Test(org.junit.Test)

Example 14 with TableTuple

use of main.database.TableTuple in project Info-Evaluation by TechnionYP5777.

the class AnalyzeParagragh method Analyze.

public TableTuple Analyze() {
    /*
		 * First step is initiating the Stanford CoreNLP pipeline (the pipeline
		 * will be later used to evaluate the text and annotate it) Pipeline is
		 * initiated using a Properties object which is used for setting all
		 * needed entities, annotations, training data and so on, in order to
		 * customized the pipeline initialization to contains only the models
		 * you need
		 */
    final Properties props = new Properties();
    /*
		 * The "annotators" property key tells the pipeline which entities
		 * should be initiated with our pipeline object, See
		 * http://nlp.stanford.edu/software/corenlp.shtml for a complete
		 * reference to the "annotators" values you can set here and what they
		 * will contribute to the analyzing process
		 */
    props.put("annotators", "tokenize,ssplit, pos, regexner, parse,lemma,natlog,openie");
    final StanfordCoreNLP pipeLine = new StanfordCoreNLP(props);
    // inputText will be the text to evaluate in this example
    final String inputText = input + "";
    final Annotation document = new Annotation(inputText);
    // Finally we use the pipeline to annotate the document we created
    pipeLine.annotate(document);
    final String $ = getName();
    final String input_date = getDate(year);
    String reason = "";
    // more details about the reason. e.g - where it
    String details = "";
    // happened.
    String aux = "";
    String accurate_name = "";
    for (final CoreMap sentence : document.get(SentencesAnnotation.class)) {
        final SemanticGraph dependencies = sentence.get(CollapsedDependenciesAnnotation.class);
        for (final IndexedWord root : dependencies.getRoots()) for (final SemanticGraphEdge edge : dependencies.getOutEdgesSorted(root)) {
            final IndexedWord dep = edge.getDependent();
            final String rel = edge.getRelation() + "";
            if (!"arrested".equals(edge.getGovernor().word()))
                switch(rel) {
                    case "nmod:in":
                        details += "in" + " " + dep.word() + " ";
                        break;
                    case "nmod:during":
                        details += "during" + " " + dep.word() + " ";
                        break;
                    case "nmod:at":
                        details += "at" + " " + dep.word() + " ";
                        break;
                }
            else {
                //Finding the name in a more accurate manner:
                if ("nsubjpass".equals(rel)) {
                    for (final SemanticGraphEdge keshet : dependencies.getOutEdgesSorted(dep)) {
                        final IndexedWord dep2 = keshet.getDependent();
                        final String rel2 = keshet.getRelation() + "";
                        if ((dep2.ner() != null && "PERSON".equals(dep2.ner())) || "compound".equals(rel2) || "det".equals(rel2))
                            accurate_name += dep2.word() + " ";
                    }
                    accurate_name += dep.word();
                }
                //Finding the reason in the paragraph
                if ("advcl".equals(rel) || "advcl:for".equals(rel) || "nmod:for".equals(rel)) {
                    for (final SemanticGraphEdge keshet : dependencies.getOutEdgesSorted(dep)) {
                        final String rel2 = keshet.getRelation() + "";
                        final IndexedWord dep2 = keshet.getDependent();
                        if ("amod".equals(rel2) || "dobj".equals(rel2))
                            reason += dep2.word() + " ";
                        if ("xcomp".equals(rel2))
                            aux += " " + dep2.word();
                        switch(rel2) {
                            case "nmod:in":
                                final String longLocation = dep2.word();
                                details += "in ";
                                for (final SemanticGraphEdge keshet2 : dependencies.getOutEdgesSorted(dep2)) if ("compound".equals(keshet2.getRelation() + ""))
                                    details += keshet2.getDependent().word() + " ";
                                details += longLocation;
                                break;
                            case "nmod:during":
                                details += "during" + " " + dep2.word() + " ";
                                break;
                            case "nmod:under":
                                details += "under " + dep2.word() + " ";
                                break;
                            case "nmod:of":
                                details += "of " + dep2.word();
                                break;
                            case "nmod:at":
                                details += "at" + " " + dep2.word() + " ";
                                break;
                        }
                        if ("suspicion".equals(keshet.getSource().word()) && "acl:of".equals(rel2))
                            details += dep2.word();
                    }
                    reason += dep.word();
                    reason += aux;
                }
            }
        }
    }
    return new TableTuple(accurate_name.isEmpty() ? $ : accurate_name, input_date, (reason + " " + details).trim());
}
Also used : TableTuple(main.database.TableTuple) InteractiveTableTuple(main.database.InteractiveTableTuple) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) Properties(java.util.Properties) IndexedWord(edu.stanford.nlp.ling.IndexedWord) CoreMap(edu.stanford.nlp.util.CoreMap) StanfordCoreNLP(edu.stanford.nlp.pipeline.StanfordCoreNLP) SentencesAnnotation(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) CollapsedDependenciesAnnotation(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation) SemanticGraphEdge(edu.stanford.nlp.semgraph.SemanticGraphEdge)

Example 15 with TableTuple

use of main.database.TableTuple in project Info-Evaluation by TechnionYP5777.

the class MainFrame method initialize.

/**
	 * Initialize the contents of the frame.
	 */
private void initialize() {
    /*
		 * this flag to change the name of search button
		 */
    startFlag = false;
    frame = new JFrame();
    frame.setTitle("Info Evaluation");
    frame.setResizable(false);
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setBounds(0, 0, screen.width, screen.height - 1);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try {
        connector = new MySQLConnector();
    } catch (final Exception e) {
        JOptionPane.showMessageDialog(null, "problem with sql connector", "Error", JOptionPane.INFORMATION_MESSAGE);
    }
    frame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent winEvt) {
            try {
                clearDB();
            } catch (final SQLException e) {
                JOptionPane.showMessageDialog(null, "problem with removing events from Database", "Error", JOptionPane.INFORMATION_MESSAGE);
            }
            closeConnection();
            System.exit(0);
        }
    });
    final AnalyzeSources events = new AnalyzeSources();
    events.addSource(src1);
    events.addSource(src2, "2015");
    MySQLConnector.addEvents(events.getData());
    try {
        addAllKeywords(events.getData());
    } catch (SQLException ¢) {
        ¢.printStackTrace();
    }
    final JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);
    mntmAbout = new JMenuItem("About");
    mnHelp.add(mntmAbout);
    popupMenu = new JPopupMenu();
    mnfilter = new JMenuItem("Filter by");
    mnprofile = new JMenuItem("View profile");
    mnprofile.setVisible(false);
    popupMenu.add(mnfilter);
    popupMenu.add(mnprofile);
    /*
		 *
		 * initializing the table
		 *
		 */
    // {
    table = new JTable();
    table.setComponentPopupMenu(popupMenu);
    table.setShowVerticalLines(false);
    table.setCellSelectionEnabled(true);
    table.setColumnSelectionAllowed(true);
    table.setBorder(new LineBorder(null));
    for (int count = 1; count <= 10; ++count) table.setModel(new DefaultTableModel(new Object[][] { { "Name", "Date", "Reason" } }, new String[] { "Name", "Date", "Reason" }));
    table.setBounds(30, 120, screen.width / 2 + 100, screen.height / 2);
    table.setVisible(false);
    js = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    js.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    js.setVisible(false);
    js.setBounds(30, 120, screen.width / 2 + 100, screen.height / 2);
    frame.getContentPane().add(js);
    frame.getContentPane().add(js);
    /*
		 * initializing the table
		 *
		 */
    inputList = new RefineTable();
    inputList.addField("Date");
    inputList.addField("Name");
    inputList.addField("Reason");
    inputList.addField("Year");
    btnSearch = new JButton("Load analyze results");
    searchTxt = new JTextField(10);
    searchTxt.setText("Select checkBox to search");
    searchTxt.setColumns(10);
    searchTxt.setEditable(false);
    ArrayList<String> keywords = new ArrayList<String>();
    for (TableTuple t : events.getData()) {
        String year = t.getDate().split("/")[2];
        if (!keywords.contains(year))
            keywords.add(year);
        if (!keywords.contains(t.getName()))
            keywords.add(t.getName());
        for (String s : t.getKeyWords()) for (String key : s.split(" ")) {
            if (keywords.contains(key))
                continue;
            keywords.add(key);
        }
    }
    AutoComplete.setupAutoComplete(searchTxt, keywords);
    chckbxName = new JCheckBox("Name");
    chckbxName.setVisible(false);
    chckbxDate = new JCheckBox("Date");
    chckbxDate.setVisible(false);
    chckbxReason = new JCheckBox("Reason");
    chckbxReason.setVisible(false);
    chckbxSortby = new JCheckBox("Sort by");
    chckbxFilterBy = new JCheckBox("Filter by");
    comboBox = new JComboBox<>();
    comboBox.setVisible(false);
    txtpnChooseOneFrom = new JTextPane();
    txtpnChooseOneFrom.setText("Choose one from:");
    txtpnChooseOneFrom.setBackground(new Color(0, 0, 0, 0));
    txtpnChooseOneFrom.setVisible(false);
    personalInfo = new InfoExtractor();
    btnLoadAnalyzeResults = new JButton("Load analyze results");
    btnLoadAnalyzeResults.setVisible(false);
    /*
		 * add image
		 */
    BufferedImage myPicture;
    try {
        myPicture = ImageIO.read(this.getClass().getResource("images/search.png"));
        lblImage = new JLabel(new ImageIcon(myPicture.getScaledInstance(220, 220, Image.SCALE_DEFAULT)));
    } catch (IOException ¢) {
        ¢.printStackTrace();
    }
    chckbxSearch = new JCheckBox("");
    btnAddEvents = new JButton("Add Events");
    final GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
    groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addContainerGap(881, Short.MAX_VALUE).addComponent(lblImage, GroupLayout.PREFERRED_SIZE, 232, GroupLayout.PREFERRED_SIZE).addGap(247)).addGroup(groupLayout.createSequentialGroup().addGap(30).addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addComponent(btnLoadAnalyzeResults).addGap(92).addComponent(btnAddEvents, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE)).addGroup(groupLayout.createSequentialGroup().addComponent(chckbxSearch, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED).addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false).addComponent(searchTxt, GroupLayout.PREFERRED_SIZE, 744, GroupLayout.PREFERRED_SIZE).addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false).addGroup(groupLayout.createSequentialGroup().addComponent(chckbxName).addGap(18).addComponent(chckbxDate, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(groupLayout.createSequentialGroup().addComponent(chckbxSortby).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(chckbxFilterBy))).addPreferredGap(ComponentPlacement.RELATED).addComponent(chckbxReason).addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(txtpnChooseOneFrom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))).addGap(18).addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(btnSearch, GroupLayout.PREFERRED_SIZE, 224, GroupLayout.PREFERRED_SIZE).addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 219, GroupLayout.PREFERRED_SIZE)))).addContainerGap(313, Short.MAX_VALUE)));
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addGroup(groupLayout.createSequentialGroup().addContainerGap().addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false).addComponent(chckbxSearch).addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(searchTxt, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE).addComponent(btnSearch, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(chckbxSortby).addComponent(chckbxFilterBy)).addPreferredGap(ComponentPlacement.RELATED).addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(txtpnChooseOneFrom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(chckbxName).addComponent(chckbxDate).addComponent(chckbxReason)).addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))).addPreferredGap(ComponentPlacement.RELATED, 177, Short.MAX_VALUE).addComponent(lblImage, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE).addGap(76).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(btnLoadAnalyzeResults, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE).addComponent(btnAddEvents, GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)).addGap(171)));
    frame.getContentPane().setLayout(groupLayout);
}
Also used : ImageIcon(javax.swing.ImageIcon) SQLException(java.sql.SQLException) LineBorder(javax.swing.border.LineBorder) DefaultTableModel(javax.swing.table.DefaultTableModel) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) JTextField(javax.swing.JTextField) BufferedImage(java.awt.image.BufferedImage) JTextPane(javax.swing.JTextPane) JFrame(javax.swing.JFrame) GroupLayout(javax.swing.GroupLayout) MySQLConnector(main.database.MySQLConnector) JMenuItem(javax.swing.JMenuItem) JScrollPane(javax.swing.JScrollPane) Color(java.awt.Color) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) AnalyzeSources(main.Analyze.AnalyzeSources) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JPopupMenu(javax.swing.JPopupMenu) Point(java.awt.Point) JCheckBox(javax.swing.JCheckBox) TableTuple(main.database.TableTuple) WindowEvent(java.awt.event.WindowEvent) JTable(javax.swing.JTable) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

TableTuple (main.database.TableTuple)27 Test (org.junit.Test)22 Sentence (edu.stanford.nlp.simple.Sentence)12 AnalyzeParagragh (main.Analyze.AnalyzeParagragh)12 DataList (main.database.DataList)7 AnalyzeSources (main.Analyze.AnalyzeSources)4 InteractiveTableTuple (main.database.InteractiveTableTuple)3 IOException (java.io.IOException)2 Before (org.junit.Before)2 SentencesAnnotation (edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation)1 IndexedWord (edu.stanford.nlp.ling.IndexedWord)1 Annotation (edu.stanford.nlp.pipeline.Annotation)1 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)1 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)1 CollapsedDependenciesAnnotation (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation)1 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)1 CoreMap (edu.stanford.nlp.util.CoreMap)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1