Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

added 2 characters in body
Source Link
alvas
  • 123.5k
  • 118
  • 504
  • 810

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT, PRIMARY KEY (sid))")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO CarsCorpus VALUES("+sid+","+scid+"'"+sent+"')")

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT, PRIMARY KEY (sid))")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO Cars VALUES("+sid+","+scid+"'"+sent+"')")

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT, PRIMARY KEY (sid))")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO Corpus VALUES("+sid+","+scid+"'"+sent+"')")
deleted 54 characters in body
Source Link
alvas
  • 123.5k
  • 118
  • 504
  • 810

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT, PRIMARY KEY (sid))")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO Cars VALUES("+sid+","+scid+"'"+sent+"')")

Does my sid get PRIMARY KEY when i executed the CREATE TABLE ...?

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT)")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO Cars VALUES("+sid+","+scid+"'"+sent+"')")

Does my sid get PRIMARY KEY when i executed the CREATE TABLE ...?

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT, PRIMARY KEY (sid))")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO Cars VALUES("+sid+","+scid+"'"+sent+"')")
Source Link
alvas
  • 123.5k
  • 118
  • 504
  • 810

How to put a textfile into sqlite simply using Python API?

I have a tab delimited file in the format:

sentenceID (sid) documentID (scid) sentenceText (sent)

E.g.

100004 100 即便您喜爱流连酒吧,也定然在这轻松安闲的一隅,来一场甜蜜沉醉的约会。
100005 100 您可以慢慢探究菜单上所有的秘密惊喜。

I want to put it into sqlite3 with the following schema:

CREATE TABLE sent (
 sid INTEGER PRIMARY KEY,
 scid INTEGER,
 sent TEXT,
 );

Is there a quick way to use the python API for sqlite (http://docs.python.org/2/library/sqlite3.html) to put them into a table?

I've been doing it as such:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys, codecs
con = lite.connect('mycorpus.db')
with con: 
 cur = con.cursor()
 cur.execute("CREATE TABLE Corpus(sid INT, scid INT, sent TEXT)")
 for line in codecs.read('corpus.tab','r','utf8'):
 sid,scid,sent = line.strip().split("\t")
 cur.execute("INSERT INTO Cars VALUES("+sid+","+scid+"'"+sent+"')")

Does my sid get PRIMARY KEY when i executed the CREATE TABLE ...?

default

AltStyle によって変換されたページ (->オリジナル) /