-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf58d11
commit f13c1f7
Showing
8 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package libiada.DiffBuildingAnalysis; | ||
|
||
import libiada.DiffBuildingAnalysis.Iterators.CutRuleIterator; | ||
import libiada.DiffBuildingAnalysis.Rules.CutRule; | ||
import libiada.IntervalAnalysis.Chain; | ||
|
||
import javax.mail.search.StringTerm; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 18.10.11 | ||
* Time: 12:46 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class DifCutter { | ||
public ArrayList<String> cut(String chain, CutRule rule) { | ||
ArrayList<String> result = new ArrayList<String>(); | ||
|
||
rule.getIterator(); | ||
CutRuleIterator iterator = rule.getIterator(); | ||
|
||
while(iterator.next()) | ||
{ | ||
String s = chain.substring(iterator.getStartPos()-1, iterator.getStopPos()); | ||
result.add(s); | ||
} | ||
return result; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/libiada/DiffBuildingAnalysis/Iterators/CutRuleIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package libiada.DiffBuildingAnalysis.Iterators; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 18.10.11 | ||
* Time: 13:55 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class CutRuleIterator { | ||
private ArrayList<Integer> starts; | ||
private ArrayList<Integer> stops; | ||
private int i = -1; | ||
|
||
public CutRuleIterator(ArrayList<Integer> starts, ArrayList<Integer> stops) { | ||
this.starts = starts; //храним начальные позиции | ||
this.stops = stops; //храним конечные позиции | ||
|
||
} | ||
|
||
public boolean next() { | ||
i++; | ||
return (starts.size() > i) && (stops.size() > i); | ||
} | ||
|
||
public int getStartPos() { | ||
return starts.get(i); | ||
} | ||
|
||
public int getStopPos() { | ||
return stops.get(i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package libiada.DiffBuildingAnalysis.Rules; | ||
|
||
import libiada.DiffBuildingAnalysis.Iterators.CutRuleIterator; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 18.10.11 | ||
* Time: 12:58 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public abstract class CutRule { | ||
protected ArrayList<Integer> starts = new ArrayList<Integer>(); | ||
protected ArrayList<Integer> stops = new ArrayList<Integer>(); | ||
|
||
public abstract CutRuleIterator getIterator(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/libiada/DiffBuildingAnalysis/Rules/FromFixStartCutRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package libiada.DiffBuildingAnalysis.Rules; | ||
|
||
import libiada.DiffBuildingAnalysis.Iterators.CutRuleIterator; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 18.10.11 | ||
* Time: 13:23 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class FromFixStartCutRule extends CutRule { | ||
public FromFixStartCutRule(int length, int step) { | ||
for (int i=1 ; i<=length/step; i++) | ||
{ | ||
starts.add(1); | ||
stops.add(i*step); | ||
} | ||
} | ||
|
||
@Override | ||
public CutRuleIterator getIterator() { | ||
return new CutRuleIterator(starts, stops); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package rapidminer.chain; | ||
|
||
import com.rapidminer.example.Example; | ||
import com.rapidminer.example.ExampleSet; | ||
import com.rapidminer.example.ExampleSetFactory; | ||
import com.rapidminer.operator.Operator; | ||
import com.rapidminer.operator.OperatorDescription; | ||
import com.rapidminer.operator.OperatorException; | ||
import com.rapidminer.operator.ports.InputPort; | ||
import com.rapidminer.operator.ports.InputPorts; | ||
import com.rapidminer.operator.ports.OutputPort; | ||
import libiada.DiffBuildingAnalysis.DifCutter; | ||
import libiada.DiffBuildingAnalysis.Iterators.CutRuleIterator; | ||
import libiada.DiffBuildingAnalysis.Rules.CutRule; | ||
import libiada.DiffBuildingAnalysis.Rules.FromFixStartCutRule; | ||
|
||
import javax.management.OperationsException; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 16.11.11 | ||
* Time: 12:09 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class DifCutterRM extends Operator { | ||
protected OutputPort outChains = getOutputPorts().createPort("Chains"); | ||
protected InputPort inChain = getInputPorts().createPort("Chain"); | ||
|
||
public DifCutterRM(OperatorDescription description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public void doWork() throws OperatorException { | ||
ExampleSet examples = inChain.getData(); //со входного порта считали информацицию, получили таблицу | ||
Example example = examples.getExample(0); //получили строчку таблицы данных | ||
String s = example.getValueAsString(examples.getAttributes().get("Chain")); | ||
DifCutter dif = new DifCutter(); //рубит строчку | ||
FromFixStartCutRule rule = new FromFixStartCutRule(s.length(), 100); //првило разбиения | ||
ArrayList<String> cuts = dif.cut(s, rule); //метод разрубающий строчку | ||
|
||
String[][] values = new String[cuts.size()][1]; | ||
|
||
for (int i = 0; i<cuts.size(); i++){ | ||
values[i][0] = cuts.get(i); | ||
} | ||
ExampleSet outSet = ExampleSetFactory.createExampleSet(values); | ||
outChains.deliver(outSet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package test.DiffBuildingAnalysis.Rules; | ||
|
||
import junit.framework.TestCase; | ||
import libiada.DiffBuildingAnalysis.DifCutter; | ||
import libiada.DiffBuildingAnalysis.Rules.FromFixStartCutRule; | ||
import org.junit.Test; | ||
import org.nfunk.jep.function.Str; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 16.11.11 | ||
* Time: 11:21 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class testDifCutter extends TestCase{ | ||
@Test | ||
public void testDifCutter() { | ||
String s = "reegwvwvw"; | ||
DifCutter dif = new DifCutter(); //рубит строчку | ||
FromFixStartCutRule rule = new FromFixStartCutRule(s.length(), 3); //првило разбиения | ||
ArrayList<String> cuts = dif.cut(s, rule); //метод разрубающий строчку | ||
|
||
assertEquals(cuts.get(0), "ree"); //проверяем правильность результата | ||
assertEquals(cuts.get(1), "reegwv"); | ||
assertEquals(cuts.get(2), "reegwvwvw"); | ||
|
||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/DiffBuildingAnalysis.Rules/testFromFixStartCutRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package test.DiffBuildingAnalysis.Rules; | ||
|
||
import junit.framework.TestCase; | ||
import libiada.DiffBuildingAnalysis.Iterators.CutRuleIterator; | ||
import libiada.DiffBuildingAnalysis.Rules.FromFixStartCutRule; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: Vladimir | ||
* Date: 18.10.11 | ||
* Time: 13:02 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class testFromFixStartCutRule extends TestCase{ | ||
@Test | ||
public void testCutRule() throws Exception { | ||
FromFixStartCutRule rule = new FromFixStartCutRule(12, 3); | ||
CutRuleIterator iterator = rule.getIterator(); //объект, который бегает по массиву | ||
iterator.next(); | ||
assertEquals(iterator.getStartPos(), 1); | ||
assertEquals(iterator.getStopPos(), 3); | ||
iterator.next(); | ||
assertEquals(iterator.getStartPos(), 1); | ||
assertEquals(iterator.getStopPos(), 6); | ||
iterator.next(); | ||
assertEquals(iterator.getStartPos(), 1); | ||
assertEquals(iterator.getStopPos(), 9); | ||
iterator.next(); | ||
assertEquals(iterator.getStartPos(), 1); | ||
assertEquals(iterator.getStopPos(), 12); | ||
} | ||
} |