All Projects → metasoarous → Semantic Csv

metasoarous / Semantic Csv

Licence: epl-1.0
Higher level tools for working with CSV data and files

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Semantic Csv

scala-csv-parser
CSV parser library.
Stars: ✭ 24 (-89.66%)
Mutual labels:  csv, parsing
Csv
CSV Decoding and Encoding for Elixir
Stars: ✭ 398 (+71.55%)
Mutual labels:  csv, parsing
Readr
Read flat files (csv, tsv, fwf) into R
Stars: ✭ 821 (+253.88%)
Mutual labels:  csv, parsing
Dissect.cstruct
A no-nonsense c-like structure parsing library for Python
Stars: ✭ 215 (-7.33%)
Mutual labels:  parsing
Codablecsv
Read and write CSV files row-by-row or through Swift's Codable interface.
Stars: ✭ 214 (-7.76%)
Mutual labels:  csv
Useragentparser
UserAgent parsing done right
Stars: ✭ 225 (-3.02%)
Mutual labels:  parsing
Algeria Cities
The list of all Algerian provinces and cities according to the official division in different formats: csv, xlsx, php, json, etc.
Stars: ✭ 232 (+0%)
Mutual labels:  csv
Vscode Antlr4
ANTLR4 language support for Visual Studio Code
Stars: ✭ 213 (-8.19%)
Mutual labels:  parsing
Scrapysharp
reborn of https://bitbucket.org/rflechner/scrapysharp
Stars: ✭ 226 (-2.59%)
Mutual labels:  parsing
Userline
Query and report user logons relations from MS Windows Security Events
Stars: ✭ 221 (-4.74%)
Mutual labels:  csv
Docto
Simple command line utility for converting .doc & .xls files to any supported format such as Text, RTF, CSV or PDF
Stars: ✭ 220 (-5.17%)
Mutual labels:  csv
Pypacker
📦 The fastest and simplest packet manipulation lib for Python
Stars: ✭ 216 (-6.9%)
Mutual labels:  parsing
Portphp
Data import/export framework for PHP
Stars: ✭ 225 (-3.02%)
Mutual labels:  csv
Json To Csv
Nested JSON to CSV Converter
Stars: ✭ 216 (-6.9%)
Mutual labels:  csv
Gotenberg
A Docker-powered stateless API for PDF files.
Stars: ✭ 3,272 (+1310.34%)
Mutual labels:  csv
Csview
📠 A high performance csv viewer with cjk/emoji support.
Stars: ✭ 208 (-10.34%)
Mutual labels:  csv
Maigret
OSINT username checker. Collect a dossier on a person by username from a huge number of sites.
Stars: ✭ 219 (-5.6%)
Mutual labels:  parsing
Neodoc
Beautiful, hand-crafted commandline interfaces for node.js
Stars: ✭ 221 (-4.74%)
Mutual labels:  parsing
Escaya
An blazing fast 100% spec compliant, incremental javascript parser written in Typescript
Stars: ✭ 217 (-6.47%)
Mutual labels:  parsing
Spacy Api Docker
spaCy REST API, wrapped in a Docker container.
Stars: ✭ 222 (-4.31%)
Mutual labels:  parsing

Semantic CSV

Gitter

A Clojure library for higher level CSV parsing/processing functionality.

The two most popular CSV parsing libraries for Clojure presently - clojure/data.csv and clojure-csv - concern themselves only with the syntax of CSV; They take CSV text, transform it into a collection of vectors of string values, and that's it. Semantic CSV takes the next step by giving you tools for addressing the semantics of your data, helping you put it in a form that better reflects what it represents.

See the introductory blog post for more information on the design philosophy.

Features

  • Absorb header row as a vector of column names, and return remaining rows as maps of column-name -> row-val
  • Write from a collection of maps, given a header
  • Apply casting/formatting functions by column name, while reading or writing
  • Remove commented out lines (by default, those starting with #)
  • Compatible with any CSV parsing library returning/writing a sequence of row vectors
  • Transducer versions of all the main functions by requiring semantic-csv.transducers instead of semantic-csv.core
  • (UNTESTED) Cljs compatibility
  • (SOON) A "sniffer" that reads in N lines, and uses them to guess column types

Structure

Semantic CSV is structured around a number of composable processing functions for transforming data as it comes out of or goes into a CSV file. This leaves room for you to use whatever parsing/formatting tools you like, reflecting a nice decoupling of grammar and semantics. However, a couple of convenience functions are also provided which wrap these individual steps in an opinionated but customizable manner, helping you move quickly while prototyping or working at the REPL.

Installation

Assuming you're using Leiningen, just add the following to your dependencies:

Clojars Project

Note that this release is still in alpha and is subject to change. If you would like a stable release, please use 0.1.0 (and note that 0.2.0 was an accidental release and was supposed to be alpha). We're hoping to have a stable 0.2.1 release soon.

Usage

Please see metasoarous.github.io/semantic-csv for complete documentation.

Semantic CSV emphasizes a number of individual processing functions which can operate on the output of a syntactic csv parser such as clojure.data.csv or clojure-csv. This reflects a nice decoupling of grammar and semantics, in an effort to make this library as composable and interoperable as possible.

=> (require '[clojure.java.io :as io]
            '[clojure-csv.core :as csv]
            '[semantic-csv.core :as sc])
            
=> (with-open [in-file (io/reader "test/test.csv")]
     (->>
       (csv/parse-csv in-file)
       (sc/remove-comments)
       (sc/mappify)
       (sc/cast-with {:this ->int})
       doall))

({:this 1, :that "2", :more "stuff"}
 {:this 2, :that "3", :more "other yeah"})

However, some opinionated, but configurable convenience functions are also provided.

(with-open [in-file (io/reader "test/test.csv")]
  (doall
    (sc/process (parse-csv in-file))))

And for the truly irreverent... (who don't need computer laziness):

(sc/slurp-csv "test/test.csv")

Writing CSV data

As with the input processing functions, the writer processing functions come in modular pieces you can use as you see fit. This time let's use clojure/data.csv:

(require '[semantic-csv.core :as sc]
         '[clojure.data.csv :as cd-csv])

(def data [{:this 1, :that "2", :more "stuff"}
           {:this 2, :that "3", :more "other yeah"}])

(with-open [out-file (io/writer "test.csv")]
  (->> data
       (sc/cast-with {:this #(-> % float str)})
       sc/vectorize
       (cd-csv/write-csv out-file)))

And again, as with the input processing functions, here we also provide a quick and dirty, opinionated convenience function for automating some of this:

(sc/spit-csv "test2.csv"
          {:cast-fns {:this #(-> % float str)}}
          data)

And there you have it.

Transducer API

There is now a transducer API available under the semantic-csv.transducers namespace. This API is now (or will soon be) in public alpha. The API is still subject to change, but we would greatly appreciate feedback.

In particular, we'd appreciate the following feedback:

  • should transducers hook up differently to io? io is sort of a "reducible" context...
  • how should the namespaces be organized? the transformer versions current live in a mirror api as the core api.

Please see metasoarous.github.io/semantic-csv for complete documentation.

Contributing

Feel free to submit a pull request. If you're looking for things to help with, please take a look at the GH issues page. Contributing to the issues with comments, feedback, or requests is also greatly appreciated.

Contributors

For a complete list of contributors, see the GH contributors page.

Of particular note, however:

License

Copyright © 2014-2017 Christopher Small

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].