Package org.apache.jena.atlas.csv

Examples of org.apache.jena.atlas.csv.CSVParser


    }

  @Override
  public void parse() {
     sink.start() ;
     CSVParser parser = ( input != null ) ? CSVParser.create(input) : CSVParser.create(reader) ;
     List<String> row = null ;
     ArrayList<Node> predicates = new ArrayList<Node>();
     int rowNum = 0;
     while ( (row=parser.parse1())!=null) {
       rowNum++;
       if (rowNum==1){
         for (String column: row){
           Node predicate = this.profile.createURI(filename + "#" + column.trim(), rowNum, 0);
           predicates.add(predicate);
View Full Code Here


{
    // This code exists to support the SPARQL WG tests.
    private static Logger log = LoggerFactory.getLogger(CSVInput.class) ;
    public static ResultSet fromCSV(InputStream in)
    {
        CSVParser parser = CSVParser.create(in) ;
        final List<Var> vars = vars(parser) ;
        List<String> varNames = Var.varNames(vars) ;
        Transform<List<String>, Binding> transform = new Transform<List<String>, Binding>(){
            private int count = 1 ;
            @Override
View Full Code Here

        return vars ;
    }
   
    public static boolean booleanFromCSV(InputStream in)
    {
        CSVParser parser = CSVParser.create(in) ;
        final List<Var> vars = vars(parser) ;
        if ( vars.size() != 1 ) {
            throw new ARQException("CSV Boolean Results malformed: variables line='"+vars+"'") ;
        }
        if ( ! vars.get(0).getName().equals("_askResult")) {
            FmtLog.warn(log, "Boolean result variable is '%s', not '_askResult'", vars.get(0).getName()) ;
        }
       
       
        List<String> line = parser.parse1() ;
        if ( line.size() != 1 ) {
            throw new ARQException("CSV Boolean Results malformed: data line='"+line+"'") ;
        }
        String str = line.get(0) ;
        boolean b ;
        if ( str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes") )
            b = true ;
        else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("no"))
            b = false;
        else {
            throw new ARQException("CSV Boolean Results malformed, expected one of - true yes false no - but got " + str);
            }
       
        List<String> line2 = parser.parse1() ;
        if ( line2 != null ) {
            FmtLog.warn(log, "Extra rows: first is "+line2) ;
        }
        return b ;
    }
View Full Code Here

  }

  @Override
  public void parse() {
    sink.start();
    CSVParser parser = (input != null) ? CSVParser.create(input)
        : CSVParser.create(reader);
    List<String> row = null;
    ArrayList<Node> predicates = new ArrayList<Node>();
    int rowNum = 0;
    while ((row = parser.parse1()) != null) {
     
      if (rowNum == 0) {
        for (String column : row) {
          String uri = IRIResolver.resolveString(filename) + "#"
              + toSafeLocalname(column);
View Full Code Here

    PropertyTable table = createEmptyPropertyTableArrayImpl(csvFilePath);
    return fillPropertyTable(table, csvFilePath);
  }
 
  private static PropertyTable createEmptyPropertyTableArrayImpl (String csvFilePath) {
    CSVParser parser = CSVParser.create(csvFilePath);
    List<String> rowLine = null;
    int rowNum = 0;
    int columnNum = 0;
   
    while ((rowLine = parser.parse1()) != null) {
      if (rowNum == 0) {
        columnNum = rowLine.size();
      }
      rowNum++;
    }
View Full Code Here

 
  protected static PropertyTable fillPropertyTable(PropertyTable table, CSVTokenIterator iterator, String csvFilePath){
    if (table == null){
      return null;
    }
    CSVParser parser = new CSVParser (iterator);
    List<String> rowLine = null;
    ArrayList<Node> predicates = new ArrayList<Node>();
    int rowNum = 0;

    while ((rowLine = parser.parse1()) != null) {
      if (rowNum == 0) {
        table.createColumn(CSV_ROW_NODE);
        for (String column : rowLine) {
          String uri = createColumnKeyURI(csvFilePath, column);
          Node p = NodeFactory.createURI(uri);
View Full Code Here

{
    // This code exists to support the SPARQL WG tests.
    private static Logger log = LoggerFactory.getLogger(CSVInput.class) ;
    public static ResultSet fromCSV(InputStream in)
    {
        CSVParser parser = CSVParser.create(in) ;
        final List<Var> vars = vars(parser) ;
        List<String> varNames = Var.varNames(vars) ;
        Transform<List<String>, Binding> transform = new Transform<List<String>, Binding>(){
            private int count = 1 ;
            @Override
View Full Code Here

        return vars ;
    }
   
    public static boolean booleanFromCSV(InputStream in)
    {
        CSVParser parser = CSVParser.create(in) ;
        final List<Var> vars = vars(parser) ;
        if ( vars.size() != 1 ) {
            throw new ARQException("CSV Boolean Results malformed: variables line='"+vars+"'") ;
        }
        if ( ! vars.get(0).getName().equals("_askResult")) {
            FmtLog.warn(log, "Boolean result variable is '%s', not '_askResult'", vars.get(0).getName()) ;
        }
       
       
        List<String> line = parser.parse1() ;
        if ( line.size() != 1 ) {
            throw new ARQException("CSV Boolean Results malformed: data line='"+line+"'") ;
        }
        String str = line.get(0) ;
        boolean b ;
        if ( str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes") )
            b = true ;
        else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("no"))
            b = false;
        else {
            throw new ARQException("CSV Boolean Results malformed, expected one of - true yes false no - but got " + str);
            }
       
        List<String> line2 = parser.parse1() ;
        if ( line2 != null ) {
            FmtLog.warn(log, "Extra rows: first is "+line2) ;
        }
        return b ;
    }
View Full Code Here

  }

  @Override
  public void parse() {
    sink.start();
    CSVParser parser = (input != null) ? CSVParser.create(input)
        : CSVParser.create(reader);
    List<String> row = null;
    ArrayList<Node> predicates = new ArrayList<Node>();
    int rowNum = 0;
    while ((row = parser.parse1()) != null) {
     
      if (rowNum == 0) {
        for (String column : row) {
          String uri = IRIResolver.resolveString(filename) + "#"
              + toSafeLocalname(column);
View Full Code Here

TOP

Related Classes of org.apache.jena.atlas.csv.CSVParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.