Skip to content

Commit

Permalink
format the output data
Browse files Browse the repository at this point in the history
Output to pipe delimited table
  • Loading branch information
adeagbot committed Jan 18, 2016
1 parent 98b17d7 commit c089f18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/main/java/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Runner {
public static void main(String args[]){

//if(args.length==2){
main.scala.Wife.main(args);
//main.scala.Wife.main(args);
main.scala.Swift.main(args);
// }else{
// System.err.println("Arguments missing from command");
Expand Down
10 changes: 7 additions & 3 deletions src/main/scala/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,24 @@ object Parser {
}{
if(kind=="block"){
if(!block.isEmpty()){
if(level==1 && block=="1"){
if(level==1 && block=="1" || block=="2"){
array+=(( block, field, valuesSoFar))
} else{
array+=((parent , block, valuesSoFar))
if(field.isEmpty())
array+=((parent , block, valuesSoFar))
else
array+=((parent , field, valuesSoFar))
}
}
if(level==1)parent=value
block = value
field = ""
valuesSoFar = ""
}else if(kind=="field"){

if(block.isEmpty()){//TO DO
//raise Error(u'block for field "%s" must be specified' % value)
}else{
}else{
if(!field.isEmpty()){
array+=((parent, field, valuesSoFar))
}
Expand Down
48 changes: 19 additions & 29 deletions src/main/scala/Swift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,32 @@ import scala.collection.mutable.ArrayBuffer
import scala.io.Source
import scala.collection.mutable.Map


object Swift extends App{

//val file=this.args(0);
val filename = System.getProperty("user.dir")+
File.separator+"src"+
File.separator+"main"+
File.separator+"resources"+
File.separator+"MT101.txt";

val list=Parser.structuredItems(Parser.messageItems(Source.fromFile(filename)))
list.foreach(println)

// def fold(list:Array[(Int,String,String,String)])
// //:Array[(Int,String,String,String)]
// ={
// val array = ArrayBuffer[(Int,String,String,String,Map[String,String])]()
// for (i<-0 to list.length-1 ){
// val map=Map.empty[String,String]
// if(list(i)._4.isEmpty()){
// //val map=Map.empty[String,String]
// for (j<-i+1 to list.length-1){
// if(list(i)._1!=list(j)._1){
// map+=(list(j)._3->list(j)._4)
// }
// }
// for ((k,v) <- map){
// println(k+" :"+v)
// }
// println("end")
// map.empty
// }else {
// //
// //array+=(list(i)._1,list(i)._2,list(i)._3,list(i)._4,map)
// }
// }
// array.toArray
// }
list.filter(!_._3.isEmpty())
.map(i=>(i._1,i._2,"",i._3))
.flatMap(i=>{
val a=i._4.split("\r")
val length=a.length;
if(length>1){
val array = ArrayBuffer[(String,String,String,String)]()
a.zipWithIndex.foreach{ case(x,index) => {
val line=index+1
array.append((i._1,i._2,line.toString(),a(index)))
}
}
array.toList
}else{
Array((i._1,i._2,i._3,i._4)).toList
}
})
.map(i=>i._1 +"|"+i._2+"|"+i._3+"|"+i._4)
.foreach(println)
}

0 comments on commit c089f18

Please sign in to comment.