-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 in WEBAPPS/latis from feature/LATIS-562-create-…
…a-catalog-dataset-based to dev * commit 'c495d9b16b09158725a86927b4b321f27f1dae19': Named the "ds_name" attribute in CatalogGenerator's output dataset. Corrected a comment. Add entry: "reader.catalog.class = CatalogGenerator" to latis.properties CatalogGenerator now extends DatasetAccessor; organized imports. CatalogGenerator.scala now lives in latis.reader (not writer) CatalogGenerator can now get a list of datasets for a given mission. Starting to create a CatalogGenerator class.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package latis.reader | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
import latis.dm.Dataset | ||
import latis.dm.Function | ||
import latis.dm.Index | ||
import latis.dm.Sample | ||
import latis.dm.Text | ||
import latis.ops.Operation | ||
import latis.util.FileUtils | ||
import latis.util.LatisProperties | ||
import latis.metadata.Metadata | ||
|
||
class CatalogGenerator extends DatasetAccessor { | ||
|
||
private lazy val datasetNames: List[String] = getListOfDatasets | ||
private lazy val catalogDataset: Dataset = generateCatalogDataset | ||
|
||
/** | ||
* Return the Dataset that this accessor is responsible for (catalogDataset). | ||
*/ | ||
override def getDataset(): Dataset = catalogDataset | ||
|
||
/** | ||
* Return the catalogDataset with the given Operations applied to it. | ||
*/ | ||
override def getDataset(ops: Seq[Operation]): Dataset = ops.reverse.foldRight(getDataset)(_(_)) | ||
|
||
override def close = {} | ||
|
||
//---- Helper Functions ------------------------------------------------------------------------ | ||
|
||
/* | ||
* Produce a list of the names of all datasets that live in | ||
* the "dataset.dir" as defined in latis.properties. | ||
*/ | ||
def getListOfDatasets: List[String] = { | ||
val dsdir: String = LatisProperties.getOrElse("dataset.dir", "datasets") | ||
val fileList = FileUtils.getListOfFiles(dsdir) | ||
val fileNames = ArrayBuffer[String]() | ||
|
||
for (x <- fileList) { | ||
fileNames += x.toString.substring(dsdir.length()+1, x.toString.length-5) //trim leading file path and ".tsml" | ||
} | ||
|
||
fileNames.toList | ||
} | ||
|
||
def getDatasetNames = datasetNames | ||
|
||
/* | ||
* Convert a list of dataset names into | ||
* a dataset of the form i -> ds_name | ||
*/ | ||
def generateCatalogDataset = { | ||
val samples = datasetNames.map(n => { | ||
Sample(Index(), Text(Metadata("ds_name"), n)) | ||
}) | ||
Dataset(Function(samples)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters