Пример #1
0
    def testRead(self):
        occurrence = CSVReader("data/occurrence.txt",
                               delimiter="\t",
                               quoteChar="\"",
                               indexFields=["id", "eventID"])

        indexes = occurrence.indexes()
        self.assertTrue("id" in indexes)
        self.assertTrue("eventID" in indexes)
        self.assertTrue(
            "Cruise68:Station593:EventSorbeSledge9887:Subsample16687" in
            indexes["eventID"])
        self.assertTrue(
            len(indexes["eventID"]
                ["Cruise68:Station593:EventSorbeSledge9887:Subsample16687"]) ==
            39)

        records = occurrence.getLines(
            "id", "Cruise68:Station565:EventSorbeSledge9781:Subsample17409")
        self.assertTrue(len(records) > 0)
        self.assertTrue(
            records[0]["eventID"] ==
            "Cruise68:Station565:EventSorbeSledge9781:Subsample17409")
        self.assertTrue(records[0]["scientificNameID"] ==
                        "urn:lsid:marinespecies.org:taxname:131495")

        records = occurrence.getLines(
            "eventID",
            "Cruise68:Station622:EventSorbeSledge10018:Subsample15224")
        self.assertTrue(
            records[21]["eventID"] ==
            "Cruise68:Station622:EventSorbeSledge10018:Subsample15224")
        self.assertTrue(records[21]["scientificNameID"] ==
                        "urn:lsid:marinespecies.org:taxname:120144")
Пример #2
0
 def testNotIndexed(self):
     occurrence = CSVReader("data/occurrence.txt",
                            delimiter="\t",
                            quoteChar="\"")
     with self.assertRaises(RuntimeError):
         records = list(
             occurrence.getLines(
                 "eventID",
                 "Cruise68:Station593:EventSorbeSledge9887:Subsample16687"))
Пример #3
0
    def testDev(self):
        occurrence = CSVReader("data/occurrence.txt",
                               delimiter="\t",
                               quoteChar="\"",
                               indexFields=["scientificName"])

        print occurrence.indexes()

        records = occurrence.getLines("scientificName", "Neomysis integer")
        print records
Пример #4
0
 def testFieldNamesDict(self):
     names = {"scientificName": 7}
     occurrence = CSVReader("data/occurrence.txt",
                            delimiter="\t",
                            quoteChar="\"",
                            indexFields=["scientificName"],
                            fieldNames=names)
     records = list(
         occurrence.getLines("scientificName", "Neomysis integer"))
     self.assertTrue(records[0]["scientificName"] == "Neomysis integer")
     self.assertTrue(
         records[0]["col_6"] == "urn:lsid:marinespecies.org:taxname:120136")
Пример #5
0
 def testFieldNamesList(self):
     names = [
         "id", "basisOfRecord", "occurrenceID", "sex", "lifeStage",
         "eventID"
     ]
     occurrence = CSVReader("data/occurrence.txt",
                            delimiter="\t",
                            quoteChar="\"",
                            indexFields=["eventID"],
                            fieldNames=names)
     records = list(
         occurrence.getLines(
             "eventID",
             "Cruise68:Station593:EventSorbeSledge9887:Subsample16687"))
     self.assertTrue(
         records[0]["eventID"] ==
         "Cruise68:Station593:EventSorbeSledge9887:Subsample16687")
     self.assertTrue(records[0]["occurrenceID"] == "Ugenthyperbenthos51168")
     self.assertTrue(records[0]["col_6"] == "Sagitta elegans")
Пример #6
0
from csvreader import CSVReader

#names = {"scientificName": 7}
#occurrence = CSVReader("data/occurrence.txt", delimiter="\t", quoteChar="\"", indexFields=["scientificName"], fieldNames=names)
#print occurrence.indexes()
#records = occurrence.getLines("scientificName", "Neomysis integer")
#print records

#names = ["id", "basisOfRecord", "occurrenceID", "sex", "lifeStage", "eventID", "scientificNameID", "scientificName"]
#occurrence = CSVReader("data/occurrence.txt", delimiter="\t", quoteChar="\"", indexFields=["scientificName"], fieldNames=names)
#print occurrence.indexes()
#records = occurrence.getLines("scientificName", "Neomysis integer")
#print records

names = ["id", "basisOfRecord", "occurrenceID", "sex", "lifeStage", "eventID"]
occurrence = CSVReader("data/occurrence.txt",
                       delimiter="\t",
                       quoteChar="\"",
                       indexFields=["eventID"],
                       fieldNames=names)
print occurrence.indexes()

records = occurrence.getLines(
    "eventID", "Cruise68:Station593:EventSorbeSledge9887:Subsample16687")
for r in records:
    print r

#print len(occurrence)
#for line in occurrence:
#    print line
#    break