Python sqlite3 模块,OptimizedUnicode() 实例源码

我们从Python开源项目中,提取了以下45个代码示例,用于说明如何使用sqlite3.OptimizedUnicode()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = "sterreich"
        germany = "Deutchland"
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertTrue(type(a_row[0]) == str, "type of non-ASCII row must be str")
        self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def __init__(self, filepath=None):
        if filepath==None:
            filepath = os.path.join(config.database_path, "SKIRT-runs.db")
        self._con = sqlite3.connect(filepath)
        self._con.row_factory = sqlite3.Row
        self._con.text_factory = sqlite3.OptimizedUnicode

    ## This function closes the connection to the database. Any uncommited changes are lost.
    # You can no longer use the database after calling this function.
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def __init__(self, filepath=None):
        if filepath==None:
            filepath = os.path.join(config.database_path, "SKIRT-runs.db")
        self._con = sqlite3.connect(filepath)
        self._con.row_factory = sqlite3.Row
        self._con.text_factory = sqlite3.OptimizedUnicode

    ## This function closes the connection to the database. Any uncommited changes are lost.
    # You can no longer use the database after calling this function.
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        # In py3k, str objects are always returned when text_factory
        # is OptimizedUnicode
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = "sterreich"
        germany = "Deutchland"
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), str, "type of non-ASCII row must be str")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckNonUtf8_TextFactoryOptimizedUnicode(self):
        orig_text_factory = self.con.text_factory
        try:
            try:
                self.con.text_factory = sqlite.OptimizedUnicode
                self.cur.execute("select ?", (chr(150),))
                self.fail("should have raised a ProgrammingError")
            except sqlite.ProgrammingError:
                pass
        finally:
            self.con.text_factory = orig_text_factory
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = unicode("sterreich", "latin1")
        germany = unicode("Deutchland")
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertTrue(type(a_row[0]) == unicode, "type of non-ASCII row must be unicode")
        self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsString(self):
        # ASCII -> str argument
        self.con.text_factory = sqlite.OptimizedUnicode
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), str)
        self.assertEqual(row[0], "a\x00b")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckOptimizedUnicodeAsUnicode(self):
        # Non-ASCII -> unicode argument
        self.con.text_factory = sqlite.OptimizedUnicode
        self.con.execute("delete from test")
        self.con.execute("insert into test (value) values (?)", (u\0',))
        row = self.con.execute("select value from test").fetchone()
        self.assertIs(type(row[0]), unicode)
        self.assertEqual(row[0], u\x00")
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def CheckOptimizedUnicode(self):
        # In py3k, str objects are always returned when text_factory
        # is OptimizedUnicode
        self.con.text_factory = sqlite.OptimizedUnicode
        austria = "sterreich"
        germany = "Deutchland"
        a_row = self.con.execute("select ?", (austria,)).fetchone()
        d_row = self.con.execute("select ?", (germany,)).fetchone()
        self.assertEqual(type(a_row[0]), str, "type of non-ASCII row must be str")
        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:neighborhood_mood_aws    作者:jarrellmark    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:hate-to-hugs    作者:sdoran35    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:kind2anki    作者:prz3m    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################
项目:but_sentiment    作者:MixedEmotions    | 项目源码 | 文件源码
def in_demo(trace=0, sql=True):
    """
    Select pairs of organizations and locations whose mentions occur with an
    intervening occurrence of the preposition "in".

    If the sql parameter is set to True, then the entity pairs are loaded into
    an in-memory database, and subsequently pulled out using an SQL "SELECT"
    query.
    """
    from nltk.corpus import ieer
    if sql:
        try:
            import sqlite3
            connection =  sqlite3.connect(":memory:")
            connection.text_factory = sqlite3.OptimizedUnicode
            cur = connection.cursor()
            cur.execute("""create table Locations
            (OrgName text, LocationName text, DocID text)""")
        except ImportError:
            import warnings
            warnings.warn("Cannot import sqlite; sql flag will be ignored.")


    IN = re.compile(r'.*\bin\b(?!\b.+ing)')

    print()
    print("IEER: in(ORG, LOC) -- just the clauses:")
    print("=" * 45)

    for file in ieer.fileids():
        for doc in ieer.parsed_docs(file):
            if trace:
                print(doc.docno)
                print("=" * 15)
            for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
                print(clause(rel, relsym='IN'))
                if sql:
                    try:
                        rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
                        cur.execute("""insert into Locations
                                    values (?, ?, ?)""", rtuple)
                        connection.commit()
                    except NameError:
                        pass

    if sql:
        try:
            cur.execute("""select OrgName from Locations
                        where LocationName = 'Atlanta'""")
            print()
            print("Extract data from SQL table: ORGs in Atlanta")
            print("-" * 15)
            for row in cur:
                print(row)
        except NameError:
            pass


############################################
# Example of has_role(PER, LOC)
############################################