Skip to content

Commit

Permalink
Added handleForcedContent method in AbstractExtractor. Enabling force…
Browse files Browse the repository at this point in the history
… content in SimpleEmailExtractor.
  • Loading branch information
akivela committed Apr 18, 2015
1 parent 3ae9898 commit eccb75b
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 71 deletions.
52 changes: 30 additions & 22 deletions src/org/wandora/application/tools/extractors/AbstractExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public abstract class AbstractExtractor extends AbstractWandoraTool implements W

/** Creates a new instance of AbstractExtractor */
public AbstractExtractor() {
this.wandora = Wandora.getWandora();
if(wandora != null) this.topicMap = wandora.getTopicMap();
}


Expand Down Expand Up @@ -227,6 +229,7 @@ public void handleCustomType() {
@Override
public void execute(Wandora admin, Context context) {
setWandora(admin);
if(admin != null) topicMap = admin.getTopicMap();
Object contextSource = context.getContextSource();
if(contextSource instanceof OccurrenceTextEditor) {
try {
Expand All @@ -238,7 +241,7 @@ public void execute(Wandora admin, Context context) {
if(str == null || str.length() == 0) {
str = occurrenceEditor.getText();
}
_extractTopicsFrom(str, admin.getTopicMap());
_extractTopicsFrom(str, topicMap);
}
}
catch(Exception e) {
Expand All @@ -247,31 +250,15 @@ public void execute(Wandora admin, Context context) {
}
else {
try {
this.topicMap = admin.getTopicMap();

extractionCounter = 0;
foundCounter = 0;
browseCounter = 0;

// --- EXTRACT WITH PREDEFINED CONTENT ---
if(forceUrls != null) {
handleUrls(forceUrls, topicMap);
forceUrls = null;
}

else if(forceFiles != null) {
handleFiles(forceFiles, topicMap);
forceFiles = null;
}

else if(forceContent != null){
handleContent(forceContent, topicMap);
forceContent = null;
}

// --- ASK CONTENT FOR EXTRACTION ---
else {

boolean handledForcedContent = handleForcedContent();

if(!handledForcedContent) {
// --- ASK CONTENT FOR EXTRACTION ---

int possibleTypes = getExtractorType();
extractorSourceDialog = new AbstractExtractorDialog(admin, true);
extractorSourceDialog.initialize(this);
Expand Down Expand Up @@ -332,6 +319,27 @@ else if(extractionCounter == 1) {
}


public boolean handleForcedContent() {
boolean handledForcedContent = false;
if(forceUrls != null) {
handleUrls(forceUrls, topicMap);
handledForcedContent = true;
forceUrls = null;
}
else if(forceFiles != null) {
handleFiles(forceFiles, topicMap);
handledForcedContent = true;
forceFiles = null;
}
else if(forceContent != null){
handleContent(forceContent, topicMap);
handledForcedContent = true;
forceContent = null;
}
return handledForcedContent;
}




public void handleFiles(File[] files, TopicMap tm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="confLabel">
<Properties>
<Property name="text" type="java.lang.String" value="CVS extractor options are"/>
<Property name="text" type="java.lang.String" value="CSV extractor options are"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new SimpleLabel();"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void initComponents() {

optionsPanel.setLayout(new java.awt.GridBagLayout());

confLabel.setText("CVS extractor options are");
confLabel.setText("CSV extractor options are");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public String getGUIText(int textType) {



@Override
public boolean _extractTopicsFrom(Table table, TopicMap tm) throws Exception {
if(table == null || tm == null) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.wandora.application.*;

import javax.swing.*;
import org.wandora.topicmap.TopicMap;


/**
Expand Down Expand Up @@ -67,22 +68,22 @@ public Icon getIcon() {


@Override
public void execute(Wandora admin, Context context) {
public void execute(Wandora wandora, Context context) {
int counter = 0;
try {
if(selector == null) {
selector = new DbpediaExtractorSelector(admin);
selector = new DbpediaExtractorSelector(wandora);
}
selector.setAccepted(false);
selector.setWandora(admin);
selector.setWandora(wandora);
selector.setContext(context);
selector.setVisible(true);
if(selector.wasAccepted()) {
setDefaultLogger();
WandoraTool extractor = selector.getWandoraTool(this);
if(extractor != null) {
extractor.setToolLogger(getDefaultLogger());
extractor.execute(admin, context);
extractor.execute(wandora, context);
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
*/


public class DuckDuckGoExtractor extends AbstractWandoraTool{
private DuckDuckGoExtractorUI ui = null;
public class DuckDuckGoExtractor extends AbstractWandoraTool {

private DuckDuckGoExtractorUI ui = null;


@Override
Expand All @@ -60,8 +61,8 @@ public Icon getIcon() {
return UIBox.getIcon("gui/icons/extract_duckduckgo.png");
}

private final String[] contentTypes=new String[] { "text/plain", "text/json", "application/json" };


@Override
public void execute(Wandora wandora, Context context) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="ddgLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Search query:"/>
<Property name="text" type="java.lang.String" value="Search query"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new SimpleLabel()"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public class DuckDuckGoExtractorUI extends javax.swing.JPanel {
private Context context = null;
private Wandora wandora = null;

private static final String ddgEndpoint
= "http://api.duckduckgo.com/";
private static final String ddgEndpoint = "http://api.duckduckgo.com/";

/**
* Creates new form DuckDuckGoExtractorUI
Expand Down Expand Up @@ -83,7 +82,7 @@ public WandoraTool[] getExtractors(DuckDuckGoExtractor tool) throws TopicMapExce
String query = ddgInput.getText();
String extractUrl = ddgEndpoint + "?q=" + query + "&format=json";
DuckDuckGoZeroClickExtractor ex = new DuckDuckGoZeroClickExtractor();
ex.setForceUrls(new String[]{extractUrl});
ex.setForceUrls(new String[]{ extractUrl });
wt = ex;
wts.add(wt);

Expand Down Expand Up @@ -113,7 +112,7 @@ private void initComponents() {

duckDuckGoPanel.setLayout(new java.awt.GridBagLayout());

ddgLabel.setText("Search query:");
ddgLabel.setText("Search query");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
import org.wandora.application.gui.UIBox;
import org.wandora.application.gui.WandoraOptionPane;
import org.wandora.application.tools.extractors.AbstractExtractor;


Expand Down Expand Up @@ -136,37 +137,44 @@ public Icon getIcon() {


@Override
public void execute(Wandora admin, Context context) {
if(gui == null) {
gui = new SimpleEmailExtractorPanel(admin);
}
gui.showDialog();
// WAIT TILL CLOSED

if(gui.wasAccepted()) {
int resourceType = gui.getEmailResourceType();
String resourceAddress = gui.getResourceAddress();
if(resourceAddress != null && resourceAddress.length() > 0) {
TopicMap tm = admin.getTopicMap();
try {
setDefaultLogger();
_extractTopicsFrom(new File(resourceAddress), tm, resourceType);
setState(WAIT);
public void execute(Wandora wandora, Context context) {
TopicMap tm = wandora.getTopicMap();

setTopicMap(tm);
boolean handledForcedContent = handleForcedContent();

if(!handledForcedContent) {
if(gui == null) {
gui = new SimpleEmailExtractorPanel(wandora);
}
gui.showDialog();
// WAIT TILL CLOSED

if(gui.wasAccepted()) {
int resourceType = gui.getEmailResourceType();
String resourceAddress = gui.getResourceAddress();
if(resourceAddress != null && resourceAddress.length() > 0) {
try {
setDefaultLogger();
_extractTopicsFrom(new File(resourceAddress), tm, resourceType);
setState(WAIT);
}
catch(Exception e) {
log(e);
}
}
catch(Exception e) {
log(e);
else {
log("No email resource given.");
}
}
else {
log("No email resource given.");
}
}
}





@Override
public boolean _extractTopicsFrom(URL url, TopicMap topicMap) throws Exception {
try {
URLConnection uc = null;
Expand All @@ -186,13 +194,16 @@ public boolean _extractTopicsFrom(URL url, TopicMap topicMap) throws Exception {
}


@Override
public boolean _extractTopicsFrom(String str, TopicMap topicMap) throws Exception {
_extractTopicsFromStream("http://wandora.org/si/simple-email-extractor/"+System.currentTimeMillis(), new ByteArrayInputStream(str.getBytes()), topicMap);
return true;
}


@Override
public boolean _extractTopicsFrom(File file, TopicMap topicMap) throws Exception {
System.out.println("@ _extractTopicsFrom: "+file.getAbsolutePath());
return _extractTopicsFrom(file, topicMap, SimpleEmailExtractorPanel.EMAIL_RESOURCE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
Expand Down Expand Up @@ -27,7 +27,7 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="descriptionLabel">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Simple email extractor can extract single email files and MBOX email repositories. First select resource type. Then address the email resource file and press Extract button.&lt;/html&gt;"/>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Simple email extractor can extract single email files and MBOX email repositories. First select resource type. Then locate the email resource file and press Extract button.&lt;/html&gt;"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new SimpleLabel();"/>
Expand Down Expand Up @@ -69,10 +69,10 @@
</StringArray>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[127, 20]"/>
<Dimension value="[127, 21]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 20]"/>
<Dimension value="[130, 21]"/>
</Property>
</Properties>
<AuxValues>
Expand All @@ -98,6 +98,14 @@
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="resourceTextField">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[6, 21]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[6, 21]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new SimpleField();"/>
</AuxValues>
Expand All @@ -114,13 +122,13 @@
<Insets value="[0, 2, 0, 2]"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[60, 20]"/>
<Dimension value="[70, 21]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[60, 20]"/>
<Dimension value="[70, 21]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[60, 20]"/>
<Dimension value="[70, 21]"/>
</Property>
</Properties>
<Events>
Expand Down Expand Up @@ -169,6 +177,15 @@
<Component class="javax.swing.JButton" name="extractButton">
<Properties>
<Property name="text" type="java.lang.String" value="Extract"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[70, 23]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[70, 23]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[70, 23]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="extractButtonMouseReleased"/>
Expand All @@ -185,6 +202,15 @@
<Component class="javax.swing.JButton" name="cancelButton2">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[70, 23]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[70, 23]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[70, 23]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="cancelButton2MouseReleased"/>
Expand Down
Loading

0 comments on commit eccb75b

Please sign in to comment.