diff --git a/.gitignore b/.gitignore index 2f7896d..e95bc31 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ target/ +.classpath +.project +.settings/ +.vscode/ +dbdata.txt \ No newline at end of file diff --git a/pom.xml b/pom.xml index b9b1d4d..cbaf2ed 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 @@ -25,6 +25,11 @@ 4.11 test + + org.unix4j + unix4j-command + 0.4 + @@ -79,5 +84,10 @@ + + + src/main/resources + + diff --git a/src/main/java/edu/ucl/nima/content/ReadCsv.java b/src/main/java/edu/ucl/nima/content/ReadCsv.java new file mode 100644 index 0000000..7e45134 --- /dev/null +++ b/src/main/java/edu/ucl/nima/content/ReadCsv.java @@ -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 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 lines = Unix4j.grep(regex, this.csvFile ).toLineList(); + + + String str=String.join("\n", lines); + + System.out.println("String is " + str); + + //List lines = Unix4j.grep("NINETEEN", file).toLineList(); + + // How should the return value look? + return lines; + } +} diff --git a/src/main/java/edu/ucl/nima/content/example.csv b/src/main/java/edu/ucl/nima/content/example.csv new file mode 100644 index 0000000..f23d55c --- /dev/null +++ b/src/main/java/edu/ucl/nima/content/example.csv @@ -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 . \ No newline at end of file diff --git a/src/main/java/edu/ucl/nima/people.json b/src/main/java/edu/ucl/nima/people.json new file mode 100644 index 0000000..50a859c --- /dev/null +++ b/src/main/java/edu/ucl/nima/people.json @@ -0,0 +1,3 @@ +{"name":"Michael"} +{"name":"Andy", "age":30} +{"name":"Justin", "age":19} diff --git a/src/main/resources/example.csv b/src/main/resources/example.csv new file mode 100644 index 0000000..f23d55c --- /dev/null +++ b/src/main/resources/example.csv @@ -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 . \ No newline at end of file diff --git a/src/test/java/edu/ucl/nima/content/ReadCsvTest.java b/src/test/java/edu/ucl/nima/content/ReadCsvTest.java new file mode 100644 index 0000000..563ddcc --- /dev/null +++ b/src/test/java/edu/ucl/nima/content/ReadCsvTest.java @@ -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 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 a = csv.read("M[E]{2,3}P"); + + assertEquals(2, a.size()); + } + +} \ No newline at end of file