[Ruler-commits] r67 - pkg/ruleR/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Oct 21 23:00:18 CEST 2012
Author: merysionek
Date: 2012-10-21 23:00:18 +0200 (Sun, 21 Oct 2012)
New Revision: 67
Modified:
pkg/ruleR/R/ruleR_upgraded_final.R
Log:
printing rule improved - now createTest works properly
Modified: pkg/ruleR/R/ruleR_upgraded_final.R
===================================================================
--- pkg/ruleR/R/ruleR_upgraded_final.R 2012-10-21 17:18:11 UTC (rev 66)
+++ pkg/ruleR/R/ruleR_upgraded_final.R 2012-10-21 21:00:18 UTC (rev 67)
@@ -71,19 +71,13 @@
}
}
+
setClass("DigSumSingleRule",
contains="SingleRule",
representation(description="character"),
- prototype(previousRule=new("IdenSingleRule"),description="Take the sum of digits "),
+ prototype(description="Take the sum of digits ",previousRule=new("IdenSingleRule")),
S3methods=TRUE)
-#
-# setClass("DigSumSingleRule",
-# contains="SingleRule",
-# representation(constantVal="numeric"),
-# prototype(constantVal=NULL, previousRule=new("IdenSingleRule")),
-# S3methods=TRUE)
-
setMethod("calculateSpecific",signature(x="DigSumSingleRule",y="numeric"),
function(x,y){
if(length(y) == 1){return(sum(digits(y))) ## only for one argument
@@ -155,7 +149,9 @@
#[2] MULTIPLY TWO PREVIOUS EXPRESSIONS
setClass("MultDoubleRule",
- contains="DoubleRule",
+ contains="DoubleRule",
+ representation(description="character"),
+ prototype(firstRule=new("IdenSingleRule"),secondRule=new("IdenSingleRule"),nextSingle=new("IdenSingleRule"), description="Multiply two previous elements"),
S3methods=TRUE)
@@ -275,7 +271,7 @@
} # generate 'n' if it is set as null with different probabilities
-
+
if("constantVal"%in%slotNames(singleRules[[a1]])){m<-new(singleRules[[a1]],constantVal=cv1,previousRule=new("IdenSingleRule"))
}else{m<-new(singleRules[[a1]],previousRule=new("IdenSingleRule"))}
@@ -491,6 +487,7 @@
#'index' - index of the rule in the basic rules list - it can be a list or a simple element
createDictRule<-function(index,range=c(-15:-1,1:15)){
+
if(inherits(index,"SingleRule")){rule<-index;if("constantVal"%in%slotNames(index)){range=index at constantVal}else{range=NULL}}
if(inherits(index,"DoubleRule")){rule<-index;range=NULL}
if(class(index)=="numeric"){#you specify rule from the table c(singleRules,doubleRules)
@@ -704,7 +701,7 @@
if(validation==0){#if the sequence is not unique, tru generating another one (but max. for three times)
- if(number<3) {number=number+1
+ if(number<4) {number=number+1
val(items=items,rules=rules,itemDictionary=itemDictionary,chain=chain,del=del,start=start,element_range=element_range,seqlen=seqlen,number)
}else{item<-rep(NA,seqlen)
rule<-new("IdenSingleRule")
@@ -713,9 +710,9 @@
return(k)
break
- } # if you failed to generate a unique sequence in 3 attempts- return zero sequence
+ } # if you failed to generate a unique sequence in 4 attempts- return zero sequence
}else{item<<-unlist(result)
-
+
rule<-rule
k<-list(item,rule)
@@ -784,9 +781,19 @@
function(x){
k<-list()
- desc_list<-function(x){
- if(!inherits(x,"IdenSingleRule")){k<<-c(k,paste(x at description,x at constantVal)); x<-x at previousRule;desc_list(x)}}
+ desc_list<-function(x){
+ if(!inherits(x,"IdenSingleRule")){
+ if("constantVal"%in%slotNames(x)){k<<-c(k,paste(x at description,x at constantVal)); x<-x at previousRule;desc_list(x)
+ }else {k<<-c(k,x at description); x<-x at previousRule;desc_list(x)}
+ }
+
+
+ }
+
+
+
+
desc_list(x)
for(i in length(k):1){cat(paste(k[[i]],"\n"))}
@@ -803,3 +810,16 @@
if(!inherits(x at nextSingle,"IdenSingleRule"))cat("\nRULES APPLIED TO THE RESULT OF PREVIOUS OPERATIONS:\n");print(x at nextSingle)
})
+
+
+
+
+setMethod("print",signature(x="IntertwinedRule"),
+ function(x){
+ cat("\nRULES APPLIED TO 1st,3rd,5th ... ELEMENT:\n");print(x at oddRule)
+ cat("\nRULES APPLIED TO 2nd,4th,6th ...ELEMENT:\n");print(x at evenRule)
+
+ })
+
+
+
More information about the Ruler-commits
mailing list