Skip to content
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
target/
.classpath
.project
.settings/
.vscode/
dbdata.txt
14 changes: 12 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand All @@ -25,6 +25,11 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unix4j</groupId>
<artifactId>unix4j-command</artifactId>
<version>0.4</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -79,5 +84,10 @@
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
45 changes: 45 additions & 0 deletions src/main/java/edu/ucl/nima/content/ReadCsv.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package edu.ucl.nima.content;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.unix4j.Unix4j;
import org.unix4j.line.Line;
import org.unix4j.unix.Grep;

//import reference to Unix4j class

public class ReadCsv {

//static Path p = Paths.get("example.csv");
// Path folder = p.getParent();
private static final String address = "example.csv";

File csvFile;
//TODO Create an instance variable for the csv file

public ReadCsv () {
this.csvFile=new File(ReadCsv.address);
//TODO Add a constructor for ReadCsv that accepts a String path for the csv file

// (Optional) add aconstructor that accepts a File object for csv file

}
public List<Line> read(String regex) {
//TODO reference the instance variable csv file here and grep it
// string newaddress=this.csvFile.getPath() + "src\main\java\edu\ ucl\nima\content\example.csv";
List<Line> lines = Unix4j.grep(regex, this.csvFile ).toLineList();


String str=String.join("\n", lines);

System.out.println("String is " + str);

//List<Line> lines = Unix4j.grep("NINETEEN", file).toLineList();

// How should the return value look?
return lines;
}
}
3 changes: 3 additions & 0 deletions src/main/java/edu/ucl/nima/content/example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1@@@the second jackal-based film to come out in 1997 ( the other starring bruce willis was simply entitled the jackal ) , this one stars aidan quinn and donald sutherland , and is directed by a man who hailed from joblo's own alma matter , concordia university in montreal , canada .
2@@@the story is based on the exploits of the real terrorist known as the jackal , but does not pretend to be 100% factual .
3@@@plot : naval officer ramirez ( quinn ) gets called upon by the cia to impersonate the international terrorist known as the jackal , in order to put an end to the actual militant's radical activities .
3 changes: 3 additions & 0 deletions src/main/java/edu/ucl/nima/people.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"name":"Michael"}
{"name":"Andy", "age":30}
{"name":"Justin", "age":19}
3 changes: 3 additions & 0 deletions src/main/resources/example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1@@@the second jackal-based film to come out in 1997 ( the other starring bruce willis was simply entitled the jackal ) , this one stars aidan quinn and donald sutherland , and is directed by a man who hailed from joblo's own alma matter , concordia university in montreal , canada .
2@@@the story is based on the exploits of the real terrorist known as the jackal , but does not pretend to be 100% factual .
3@@@plot : naval officer ramirez ( quinn ) gets called upon by the cia to impersonate the international terrorist known as the jackal , in order to put an end to the actual militant's radical activities .
42 changes: 42 additions & 0 deletions src/test/java/edu/ucl/nima/content/ReadCsvTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package edu.ucl.nima.content;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;
import org.unix4j.line.Line;

public class ReadCsvTest {

@Test
public void shouldRequireADataFile()
{
ReadCsv csv = new ReadCsv();

assertTrue( csv!=null );
}

@Test
public void shouldSearchFileForMatchingLines()
{
// Instantiate ReadCsv
ReadCsv csv = new ReadCsv();
List<Line> a= csv.read("MEEP");
// Verify a basic search of the csv file

assertEquals(1, a.size());
}

@Test
public void shouldSearchFileForMatchingLinesUsingRegex()
{
// Instantiate ReadCsv
ReadCsv csv = new ReadCsv();
List<Line> a = csv.read("M[E]{2,3}P");

assertEquals(2, a.size());
}

}