Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert control statement bodies to blocks #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/edu/isi/karma/cleaning/ANode.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ public void addChild(ANode a)
// all constant node and same content
public boolean isvalid()
{
if(orgPos.size()<= 1)
if(orgPos.size()<= 1){
return true;
}
for(int i=1; i<orgPos.size(); i++)
{
int value = orgPos.get(i)*orgPos.get(i-1);
if(value < 0)
if(value < 0){
return false;
}
if(orgPos.get(i) <0)
{
String sub = this.exps.get(i)[1].substring(tarPos.get(i), tarPos.get(i)+length.get(i));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/isi/karma/cleaning/DataCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public void print1()
stats.get(fname)[0] += f.learnTime;
stats.get(fname)[2] += f.genTime;
stats.get(fname)[4] += f.execTime;
if(stats.get(fname)[6] < f.exp_cnt)
if(stats.get(fname)[6] < f.exp_cnt){
stats.get(fname)[6] = (double) f.exp_cnt;
}
stats.get(fname)[7] += f.ruleNo;
stats.get(fname)[8] += f.checkedrow;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/isi/karma/cleaning/ExampleSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ public int ambiguityScore(Vector<TNode> vec) {
HashMap<String, Integer> d = new HashMap<String, Integer>();
int score = 0;
for (int i = 0; i < vec.size(); i++) {
if (d.containsKey(vec.get(i).text))
if (d.containsKey(vec.get(i).text)){
continue;
}
for (int j = 0; j < vec.size(); j++) {
if (vec.get(j).text.compareTo(vec.get(i).text) == 0 && i != j
&& vec.get(j).text.compareTo(" ") != 0) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/isi/karma/cleaning/Feature1.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public Feature1(String tar,Vector<TNode> xNodes)
public double computerScore()
{
double res = 0.0;
if(xNodes == null)
if(xNodes == null){
return 0.0;
}
for(TNode x:xNodes)
{
if(x.text.compareTo(target)==0)
if(x.text.compareTo(target)==0){
res += 1;
}
}
return res;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/isi/karma/cleaning/Feature2.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public Feature2(int type,Vector<TNode> xNodes)
public double computerScore()
{
double res = 0.0;
if(xNodes == null)
if(xNodes == null){
return 0.0;
}
for(TNode x:xNodes)
{
if(x.type == type)
if(x.type == type){
res += 1;
}
}
return res;
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/edu/isi/karma/cleaning/Loop.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public Loop mergewith(Loop a)
if(this.looptype == a.looptype)
{
Segment segment = this.loopbody.mergewith(a.loopbody);
if(segment == null)
if(segment == null){
return null;
}
Loop l = new Loop(segment, looptype);
return l;
}
Expand All @@ -42,8 +43,9 @@ public Loop mergewith(Loop a)
public Loop mergewith(Segment a)
{
Segment segment = this.loopbody.mergewith(a);
if(segment == null)
if(segment == null){
return null;
}
Loop l = new Loop(segment, looptype);
return l;
}
Expand Down Expand Up @@ -74,9 +76,9 @@ public GrammarTreeNode mergewith(GrammarTreeNode a) {
else if(a.getNodeType().compareTo("Segment")==0)
{
return this.mergewith((Segment)a);
}
else
}else{
return null;
}
}
public String getNodeType()
{
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/edu/isi/karma/cleaning/MultipleStringAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ public void generateChildren(ANode a)
length.add(e[2]-e[1]);
}
ANode aNode = new ANode(orgPos, tarPos, length, a.exps);
if(aNode.isvalid())
if(aNode.isvalid()){
a.addChild(aNode);
}
}
}
// iteratively generate the combinations
public void getCrossIndex(Vector<Long> indexs,Vector<Vector<Integer>> configs) {
int k = indexs.size();
int[] com = new int[k];
for (int i = 0; i < k; i++)
com[i] = 0;
for (int i = 0; i < k; i++){
com[i] = 0;
}
while (com[k - 1] < indexs.get(k-1)) {
Vector<Integer> res = new Vector<Integer>();
for (int i = 0; i < k; i++)
Expand All @@ -84,15 +86,17 @@ public void getCrossIndex(Vector<Long> indexs,Vector<Vector<Integer>> configs) {
}
configs.add(res);
int t = k - 1;
while (t != 0 && com[t] == indexs.get(t)-1)
t--;
while (t != 0 && com[t] == indexs.get(t)-1){
t--;
}
com[t]++;
if(t==0 && com[t] >= indexs.get(0))
{
break;
}
for (int i = t + 1; i < k; i++)
com[i] = 0;
for (int i = t + 1; i < k; i++){
com[i] = 0;
}
}
}
//{[orgstartPos, orgendPos ], ...}
Expand All @@ -105,8 +109,9 @@ public Vector<int[]> findNext(String org, String tar, int pos)
segs.add(elem);
return segs;
}
if (pos >= tar.length())
if (pos >= tar.length()){
return segs;
}
String tmp = "";
tmp += tar.charAt(pos);
// identify the const string
Expand All @@ -118,8 +123,9 @@ public Vector<int[]> findNext(String org, String tar, int pos)
tvec+= tar.charAt(cnt);
cnt++;
tmp = "";
if(cnt >= tar.length())
if(cnt >= tar.length()){
break;
}
tmp += tar.charAt(cnt);
q = org.indexOf(tmp);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/isi/karma/cleaning/OutlierDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public OutlierDetector()
}
public double getDistance(double[] x,double[] y)
{
if(x.length != y.length)
if(x.length != y.length){
return Double.MAX_VALUE;
}
double value = 0.0;
for(int i = 0; i<x.length; i++)
{
Expand Down Expand Up @@ -80,8 +81,9 @@ public String getOutliers(HashMap<String,String[]> testdata,double[] meanVector,
// pid: [{rawstring, code}]
public void buildMeanVector(HashMap<String,Vector<String[]>> data)
{
if(data == null)
if(data == null){
return;
}
for(String key:data.keySet())
{
Vector<String[]> vs = data.get(key);
Expand Down
64 changes: 41 additions & 23 deletions src/main/java/edu/isi/karma/cleaning/Position.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public Position(Vector<Integer> absPos, Vector<TNode> lcxt,
this.absPosition = absPos;
this.orgStrings.addAll(orgStrings);
this.tarStrings.addAll(tarStrings);
if (itInterpretor == null)
if (itInterpretor == null){
itInterpretor = new Interpretor();
}
// occurance of a reg pattern
this.counters.add(-1);
this.counters.add(1);
Expand Down Expand Up @@ -56,7 +57,9 @@ public void getString(Vector<TNode> x, int cur, String path, Double value,
if (!smap.keySet().contains(path)) {
String res = UtilTools.escape(path);
if (!smap.containsKey(res) && res.length() != 0)
{
smap.put(res, value); // store the string of all sizes
}
}
}
if (x == null || x.size() == 0) {
Expand All @@ -67,16 +70,18 @@ public void getString(Vector<TNode> x, int cur, String path, Double value,
if (!smap.keySet().contains(path)) {
String res = UtilTools.escape(path);
if (!smap.containsKey(res) && res.length() != 0)
{
smap.put(res, value); // store the string of all sizes
}
}
}
return;
}
TNode t = x.get(cur);
if (t.text.compareTo("ANYTOK") != 0 && t.text.length() > 0) {
if (!isleft)
if (!isleft){
getString(x, cur + 1, path + t.text, value + 2, smap, false);
else {
}else {
getString(x, cur - 1, t.text + path, value + 2, smap, true);
}
}
Expand All @@ -102,9 +107,9 @@ public void getString(Vector<TNode> x, int cur, String path, Double value,
} else {
s += "" + t.getType();
}
if (!isleft)
if (!isleft){
getString(x, cur + 1, path + s, value + 1, smap, false);
else {
}else {
getString(x, cur - 1, s + path, value + 1, smap, true);
}
}
Expand All @@ -113,9 +118,9 @@ public void getString(Vector<TNode> x, int cur, String path, Double value,
public Vector<TNode> mergeCNXT(Vector<TNode> a, Vector<TNode> b,
String option) {
Vector<TNode> xNodes = new Vector<TNode>();
if (a == null || b == null)
if (a == null || b == null){
return null;
else {
}else {
int leng = Math.min(a.size(), b.size());
if (option.compareTo(Segment.LEFTPOS) == 0) {
for (int i = 1; i <= leng; i++) {
Expand Down Expand Up @@ -161,14 +166,16 @@ public Vector<TNode> mergeCNXT(Vector<TNode> a, Vector<TNode> b,
}
}
}
if (xNodes.size() == 0)
if (xNodes.size() == 0){
return null;
}
return xNodes;
}

public Position mergewith(Position b) {
if (this == null || b == null)
if (this == null || b == null){
return null;
}
Vector<Integer> tmpIntegers = new Vector<Integer>();
tmpIntegers.addAll(this.absPosition);
tmpIntegers.retainAll(b.absPosition);
Expand All @@ -184,8 +191,9 @@ public Position mergewith(Position b) {
// this.leftContextNodes = g_lcxtNodes;
// this.rightContextNodes = g_rcxtNodes;
if (tmpIntegers.size() == 0 && g_lcxtNodes == null
&& g_rcxtNodes == null)
&& g_rcxtNodes == null){
return null;
}
boolean loop = this.isinloop || b.isinloop;

Vector<String> aStrings = new Vector<String>();
Expand Down Expand Up @@ -251,9 +259,9 @@ public double getScore() {
if (this.rightContextNodes != null) {
rsize = rightContextNodes.size();
}
if (lsize == 0 && rsize == 0)
if (lsize == 0 && rsize == 0){
return 1;
else {
}else {
for (int i = 0; i < lsize; i++) {
if (leftContextNodes.get(i).text.compareTo("ANYTOK") != 0
&& leftContextNodes.get(i).type != TNode.ANYTYP) {
Expand All @@ -277,21 +285,25 @@ public void emptyState() {
public Vector<String> rules = new Vector<String>();

public String toProgram() {
if (curState >= rules.size())
if (curState >= rules.size()){
return "null";
}
String rule = rules.get(curState);
if (!isinloop)
if (!isinloop){
rule = rule.replace("counter", counters.get(1) + "");
}
curState++;
return rule;
}

public String getRule(int index) {
if (index >= rules.size())
if (index >= rules.size()){
return "null";
}
String rule = rules.get(index);
if (!isinloop)
if (!isinloop){
rule = rule.replace("counter", counters.get(1) + "");
}
return rule;
}

Expand Down Expand Up @@ -322,23 +334,27 @@ public String VerifySpace(int itercnt) {
ProgramRule programRule = new ProgramRule(tmpRule);
String val = programRule.transform(this.orgStrings
.get(j));
if(val.indexOf("None")!= -1)
if(val.indexOf("None")!= -1){
break;
}
r += val+",";
cnt ++;
}
if(r.length()<=1)
if(r.length()<=1){
return "null";
}
if (this.tarStrings.get(j).compareTo(r.substring(0,r.length()-1)) != 0) {
isvalid = false;
break;
}
}
if (isvalid) {
if(itercnt == 0)
if(itercnt == 0){
return rule;
else
}
else {
itercnt--; // valid number - 1
}
}

} else {
Expand All @@ -353,10 +369,11 @@ public String VerifySpace(int itercnt) {
}
}
if (isValid) {
if(itercnt == 0)
if(itercnt == 0){
return rule;
else
}else{
itercnt--;
}
}
}
}
Expand Down Expand Up @@ -384,8 +401,9 @@ public void createTotalOrderVector() {
String negString = "";
for (String a : lMap.keySet()) {
for (String b : rMap.keySet()) {
if (a.compareTo(b) == 0 && a.compareTo("ANY") == 0)
if (a.compareTo(b) == 0 && a.compareTo("ANY") == 0){
continue;
}
Double key = lMap.get(a) + rMap.get(b);
reString = String.format(
"indexOf(value,\'%s\',\'%s\',counter)", a, b);
Expand Down
Loading