Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirtcats committed Nov 22, 2011
1 parent cf58d11 commit f13c1f7
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 0 deletions.
10 changes: 10 additions & 0 deletions resources/com/rapidminer/resources/OperatorsHMM.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
</group>
</group>
<group key="interval analysis">
<group key="chain operations">
<operator>
<key>
Cutter
</key>
<class>
rapidminer.chain.DifCutterRM
</class>
</operator>
</group>
<group key="chain characteristics">
<operator>
<key>Building characteristic</key>
Expand Down
31 changes: 31 additions & 0 deletions src/libiada/DiffBuildingAnalysis/DifCutter.java
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 src/libiada/DiffBuildingAnalysis/Iterators/CutRuleIterator.java
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);
}
}
19 changes: 19 additions & 0 deletions src/libiada/DiffBuildingAnalysis/Rules/CutRule.java
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 src/libiada/DiffBuildingAnalysis/Rules/FromFixStartCutRule.java
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);
}
}
52 changes: 52 additions & 0 deletions src/rapidminer/chain/DifCutterRM.java
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);
}
}
31 changes: 31 additions & 0 deletions src/test/DiffBuildingAnalysis.Rules/testDifCutter.java
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 src/test/DiffBuildingAnalysis.Rules/testFromFixStartCutRule.java
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);
}
}

0 comments on commit f13c1f7

Please sign in to comment.