Skip to content

Commit

Permalink
Merge pull request #28 from sumanthreddy542/Make-JFrames-as-internal-…
Browse files Browse the repository at this point in the history
…frames

Improve Search queries. Make import metadata frames as internal frames
  • Loading branch information
urmi-21 committed Jun 25, 2020
2 parents 265bc99 + 7ea37a1 commit ecb44c7
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 124 deletions.
52 changes: 29 additions & 23 deletions src/edu/iastate/metnet/metaomgraph/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,26 +292,26 @@ public void outputToStream(OutputStream outstream) throws IOException {
}

public Integer[] search(String term) {
return search(null, term, false);
return search(null, term, SearchMatchType.CONTAINS);
}

public Integer[] search(String field, String term, boolean exact) {
return search(new String[] { field }, new String[] { term }, new boolean[] { exact }, true);
public Integer[] search(String field, String term, SearchMatchType matchType) {
return search(new String[] { field }, new String[] { term }, new SearchMatchType[] { matchType }, true);
}

public Integer[] search(String[] fields, String[] terms, boolean[] exacts, boolean matchAll) {
public Integer[] search(String[] fields, String[] terms, SearchMatchType[] matchTypes, boolean matchAll) {
MetadataQuery[] queries = new MetadataQuery[terms.length];
for (int i = 0; i < queries.length; i++) {
String term = terms[i];
String field = null;
boolean exact = false;
SearchMatchType matchType = SearchMatchType.CONTAINS;
if (i < fields.length) {
field = fields[i];
}
if (i < exacts.length) {
exact = exacts[i];
if (i < matchTypes.length) {
matchType = matchTypes[i];
}
queries[i] = new MetadataQuery(field, term, exact,false);
queries[i] = new MetadataQuery(field, term, matchType,false);
}
return search(queries, matchAll);
}
Expand Down Expand Up @@ -517,17 +517,17 @@ public static class MetadataQuery implements Serializable, SimpleXMLizable<Metad

private String term;

private boolean exact;
private SearchMatchType matchType;

private boolean matchCase;

public MetadataQuery() {
}

public MetadataQuery(String field, String term, boolean exact,boolean matchCase) {
public MetadataQuery(String field, String term, SearchMatchType matchType,boolean matchCase) {
this.field = field;
this.term = term.trim();
this.exact = exact;
this.matchType = matchType;
this.matchCase=matchCase;
}

Expand All @@ -547,8 +547,12 @@ public void setTerm(String term) {
this.term = term;
}

public boolean isExact() {
return exact;
public SearchMatchType getMatchType() {
return matchType;
}

public void setMatchType(SearchMatchType matchType) {
this.matchType = matchType;
}

//urmi
Expand All @@ -560,14 +564,10 @@ public void setCaseSensitive(boolean flag) {
matchCase=flag;
}

public void setExact(boolean exact) {
this.exact = exact;
}

@Override
public SimpleXMLElement toXML() {
SimpleXMLElement result = new SimpleXMLElement(getXMLElementName()).setAttribute("exact",
exact ? "true" : "false");
SimpleXMLElement result = new SimpleXMLElement(getXMLElementName()).setAttribute("matchType",
matchType.toString());
if (field != null) {
result.add(new SimpleXMLElement("field").setText(field));
}
Expand All @@ -577,7 +577,7 @@ public SimpleXMLElement toXML() {

@Override
public MetadataQuery fromXML(SimpleXMLElement source) {
exact = "true".equals(source.getAttributeValue("exact"));
matchType = SearchMatchType.valueOf(source.getAttributeValue("matchType").toUpperCase());
for (int i = 0; i < source.getChildCount(); i++) {
SimpleXMLElement child = source.getChildAt(i);
if ("field".equals(child.getName())) {
Expand All @@ -599,12 +599,18 @@ public boolean matches(String field, String value) {
String thisField = getField();
if ((thisField == null) || ("".equals(thisField)) || (thisField.equalsIgnoreCase(field))) {
String term = getTerm();
if (isExact()) {
if (getMatchType() == SearchMatchType.IS) {
if (value.equalsIgnoreCase(term)) {
return true;
}
} else if (value.toLowerCase().contains(term.toLowerCase())) {
return true;
} else if (getMatchType() == SearchMatchType.CONTAINS) {
if (value.toLowerCase().contains(term.toLowerCase()))
return true;
}
else {
if (!value.equalsIgnoreCase(term)) {
return true;
}
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/edu/iastate/metnet/metaomgraph/MetadataCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,17 @@ public List<String> getDatabyAttributes(Filter filter, String targetCol, boolean
}
}

public List<String> getDatabyAttributes(String toSearch, String searchCol, String targetCol, boolean exact,
boolean uniqueFlag, boolean caseFlag) {
public List<String> getDatabyAttributes(String toSearch, String searchCol, String targetCol,
SearchMatchType matchType, boolean uniqueFlag, boolean caseFlag) {
// create filter
Filter fa = null;
if (exact) {
if (matchType == SearchMatchType.IS) {
fa = Filters.regex(searchCol, caseFlag + "^" + toSearch + "$");
} else {
} else if (matchType == SearchMatchType.CONTAINS){
fa = Filters.regex(searchCol, caseFlag + toSearch);
} else {
fa = Filters.regex(searchCol, caseFlag + "^(?!" + toSearch + "$).*$");
}

return getDatabyAttributes(fa, targetCol, uniqueFlag);
}

Expand All @@ -720,7 +721,7 @@ public List<String> getDatabyAttributes(String toSearch, String searchCol, Strin
* match all fields i.e AND operation
* @return
*/
public List<String> getDatabyAttributes(String toSearch, String targetCol, boolean exact, boolean uniqueFlag,
public List<String> getDatabyAttributes(String toSearch, String targetCol, SearchMatchType matchType, boolean uniqueFlag,
boolean AND, boolean matchCase) {
if (Arrays.asList(headers).contains(targetCol)) {
List<Document> output = null;
Expand All @@ -733,11 +734,15 @@ public List<String> getDatabyAttributes(String toSearch, String targetCol, boole
// create a filter over all cols
Filter[] fa = new Filter[this.getHeaders().length];
for (int i = 0; i < fa.length; i++) {

if (exact) {
if (matchType == SearchMatchType.IS) {
fa[i] = Filters.regex(this.getHeaders()[i], caseFlag + "^" + toSearch + "$");
} else {
} else if(matchType == SearchMatchType.CONTAINS){
fa[i] = Filters.regex(this.getHeaders()[i], caseFlag + toSearch);
} else {
// exactly not
fa[i] = Filters.regex(this.getHeaders()[i], caseFlag + "^(?!" + toSearch + "$).*$");
// not like
//fa[i] = Filters.regex(this.getHeaders()[i], caseFlag + "^(?!" + toSearch + ").*$");
}
}
if (AND) {
Expand Down Expand Up @@ -1047,7 +1052,8 @@ public static void main(String[] args) {
long startTime = System.currentTimeMillis();
for (int i = 0; i < N; i++) {
String valExpected = mogColl
.getDatabyAttributes(dc.get(i), mogColl.getDatacol(), true, true, false, true).get(0);
.getDatabyAttributes(dc.get(i), mogColl.getDatacol(),
SearchMatchType.IS, true, false, true).get(0);
if (!dc.get(i).equals(valExpected)) {
System.out.println("1Failed..." + valExpected);
}
Expand Down
40 changes: 21 additions & 19 deletions src/edu/iastate/metnet/metaomgraph/MetadataHybrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public Integer[] search(MetadataQuery[] queries, boolean matchAll) {
List<String> colVals = new ArrayList<>();
String[] allfields = new String[queries.length];
String[] toSearch = new String[queries.length];
boolean[] isExact = new boolean[queries.length];
SearchMatchType[] matchTypes = new SearchMatchType[queries.length];
boolean[] matchCase = new boolean[queries.length];
// search using Metadatacollection object and return indices of matching data
// columns from knownCols
Expand All @@ -434,12 +434,12 @@ public Integer[] search(MetadataQuery[] queries, boolean matchAll) {
for (int i = 0; i < queries.length; i++) {
allfields[i] = queries[i].getField();
toSearch[i] = queries[i].getTerm();
isExact[i] = queries[i].isExact();
matchTypes[i] = queries[i].getMatchType();
matchCase[i] = queries[i].isCaseSensitive();
// JOptionPane.showMessageDialog(null, "search f:" + fields[i]);
}

colVals.addAll(searchByValue(allfields, toSearch, this.dataColumn, isExact, matchAll, matchCase));
colVals.addAll(searchByValue(allfields, toSearch, this.dataColumn, matchTypes, matchAll, matchCase));

// JOptionPane.showMessageDialog(null, "colvals:" + colVals.toString());
// JOptionPane.showMessageDialog(null, "knownCols:" + knownCols.toString());
Expand Down Expand Up @@ -493,19 +493,19 @@ public List<String> getMatchingRows(MetadataQuery[] queries, boolean matchAll) {
List<String> colVals = new ArrayList<>();
String[] allfields = new String[queries.length];
String[] toSearch = new String[queries.length];
boolean[] isExact = new boolean[queries.length];
SearchMatchType[] matchTypes = new SearchMatchType[queries.length];
boolean[] matchCase = new boolean[queries.length];
// search using Metadatacollection object and return indices of matching data
// columns from knownCols
// do for all queries
for (int i = 0; i < queries.length; i++) {
allfields[i] = queries[i].getField();
toSearch[i] = queries[i].getTerm();
isExact[i] = queries[i].isExact();
matchTypes[i] = queries[i].getMatchType();
matchCase[i] = queries[i].isCaseSensitive();
}

colVals.addAll(searchByValue(allfields, toSearch, this.dataColumn, isExact, matchAll, matchCase));
colVals.addAll(searchByValue(allfields, toSearch, this.dataColumn, matchTypes, matchAll, matchCase));

return colVals;
}
Expand All @@ -522,7 +522,7 @@ public List<String> getMatchingRows(MetadataQuery[] queries, boolean matchAll) {
* exact match or near match?
* @return values under toReturn column where field column has value toSearch
*/
public List<String> searchByValue(String[] field, String[] toSearch, String toReturn, boolean[] exact,
public List<String> searchByValue(String[] field, String[] toSearch, String toReturn, SearchMatchType[] matchType,
boolean matchAll, boolean[] matchCase) {
List<String> res = new ArrayList<>();

Expand All @@ -540,22 +540,24 @@ public List<String> searchByValue(String[] field, String[] toSearch, String toRe
if (field[i] == "All Fields") {

// List<String> res2 = new ArrayList<>();
specialCaseRes.add(searchByValue(toSearch[i], toReturn, exact[i], true, matchCase[i]));
specialCaseRes.add(searchByValue(toSearch[i], toReturn, matchType[i], true, matchCase[i]));

} else if (field[i] == "Any Field") {

specialCaseRes.add(searchByValue(toSearch[i], toReturn, exact[i], false, matchCase[i]));
specialCaseRes.add(searchByValue(toSearch[i], toReturn, matchType[i], false, matchCase[i]));

} else {
if (exact[i]) {

if (matchType[i] == SearchMatchType.IS) {
// farray[i] = Filters.regex(field[i], "^" + toSearch[i] + "$");
filterList.add(Filters.regex(field[i], caseFlag + "^" + toSearch[i] + "$"));

} else {

} else if(matchType[i] == SearchMatchType.CONTAINS) {
filterList.add(Filters.regex(field[i], caseFlag + toSearch[i]));

} else {
// exactly not
filterList.add(Filters.regex(field[i], caseFlag + "^(?!" + toSearch[i] + "$).*$"));
// not like
//filterList.add(Filters.regex(field[i], caseFlag + "^((?!" + toSearch[i] + ").)*$"));
}
}
}
Expand Down Expand Up @@ -603,10 +605,10 @@ public List<String> searchByValue(String[] field, String[] toSearch, String toRe
return res;
}

public List<String> searchByValue(String field, String toSearch, String toReturn, boolean exact, boolean matchAll,
public List<String> searchByValue(String field, String toSearch, String toReturn, SearchMatchType matchType, boolean matchAll,
boolean matchCase) {
return searchByValue(new String[] { field }, new String[] { toSearch }, toReturn, new boolean[] { exact },
matchAll, new boolean[] { matchCase });
return searchByValue(new String[] { field }, new String[] { toSearch }, toReturn,
new SearchMatchType[] { matchType }, matchAll, new boolean[] { matchCase });

}

Expand All @@ -621,10 +623,10 @@ public List<String> searchByValue(String field, String toSearch, String toReturn
* @param matchCase
* @return
*/
public List<String> searchByValue(String toSearch, String toReturn, boolean exact, boolean matchAll,
public List<String> searchByValue(String toSearch, String toReturn, SearchMatchType matchType, boolean matchAll,
boolean matchCase) {
List<String> res = new ArrayList<>();
res = this.mogCollection.getDatabyAttributes(toSearch, toReturn, exact, true, matchAll, matchCase);
res = this.mogCollection.getDatabyAttributes(toSearch, toReturn, matchType, true, matchAll, matchCase);
return res;

}
Expand Down
15 changes: 15 additions & 0 deletions src/edu/iastate/metnet/metaomgraph/SearchMatchType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
*
*/
package edu.iastate.metnet.metaomgraph;

/**
* @author sumanth
* enum to specify match type in search
*/
public enum SearchMatchType {
CONTAINS,
IS,
NOT
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.swing.DefaultListModel;
import javax.swing.DropMode;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
Expand All @@ -44,7 +45,7 @@
import edu.iastate.metnet.metaomgraph.MetadataCollection;
import edu.iastate.metnet.metaomgraph.MetadataTreeStructure;

public class DisplayMetadataEditor extends JFrame implements ActionListener {
public class DisplayMetadataEditor extends JDialog implements ActionListener {

private JTree tree = null;
private List<String> headers;
Expand All @@ -60,6 +61,7 @@ public class DisplayMetadataEditor extends JFrame implements ActionListener {
public DisplayMetadataEditor() {
// TODO Auto-generated constructor stub
//treeStruct = MetaOmGraph.getActiveProject().returntree();
setModal(true);
this.tree = treeStruct.getTree();
this.headers = treeStruct.getList();
mogColl = MetaOmGraph.getActiveProject().getMetadataHybrid().getMetadataCollection();
Expand Down
Loading

0 comments on commit ecb44c7

Please sign in to comment.