如何从MS Access数据库中检索多个单词,并使用Python37输出单词的段落?

2024-10-03 04:27:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做什么?我用一种特殊的密码从伏尼契手稿中生成意大利语单词标签和叙述。密码包含抽象破折号&;每个字形的点数加起来等于一些与意大利语单词或英语单词低频率相关的莫尔斯电码单词。 Valid XHTML

你好,Python大师, 我已经在access中完成了一个数据库,在excel中完成了一个包含103000个意大利语单词的电子表格,我可以通过键入破折号,然后键入点序列、仅破折号序列或仅点序列来搜索,这些序列可以找到用意大利语翻译的Voynich手稿(VMS)。它的工作非常好,我可以找到一个匹配的查找或搜索意大利单词列表

例如,如果我像这样搜索。 ---...... 输出将是具有该值的所有意大利语单词的列表。”“阿丽亚”恰好是其中之一

顺便说一下,请参考较低的密码,而不是带有AriA的密码。好的,谢谢,这已经过时了

Valid XHTML

我希望在这里能得到帮助,我可以使用access数据库或电子表格来帮助生成许多意大利语叙述。我想利用我的CPU和python代码的全部潜力来访问数据库,并为Voynich段落带回尽可能多的叙述。因此,我可以选择最适合的叙述。我相信我必须将每个voynich单词输入另一个数据库或python.py文件数据库,然后让它输出一些有意义的句子。目前,我正在手动筛选搜索结果,每次查看三个单词,从第一个到第三个Voynich单词,然后根据Voynich手稿生成一个叙述,我相信这是由Michal Wojnicz编码的。这是一个缓慢而艰难的过程,但我正在为我相信Michal所写的东西造句

我在2019年7月10日从f16r的第二段开始,根据沃尼奇手稿制作了以下短句:

1)尤加内伊2)维尼塔2)哈塔提沃5)索格里6)东德吉亚瓦8)内塔曼特9)蒙坦特10)东12)斯塔塔14)埃托德罗戈号

1)…——/2) ...- . -. . - .- /3) .... .- /4) .- - - .. ...- --- /5) ... --- .-. --. . .-. . / 6). /7) - --- -. -.. . --. --. .. .- ...- .- /8) -. . - - .- -- . -. - . /9) -- --- -. - .- -. - . /10) . /11) ... . /12) ... - .- - .- /13) -. --- /14) . - - --- /15) -.. .-. --- --. ---

尤金尼安·维尼西亚拥有活跃的泉水和陡峭的山坡,其本身没有百克的药物

https://www.euganeanhills.com/

https://en.wikipedia.org/wiki/Euganean_Hills

以下是我认为需要采取的步骤:

1)我已输入所有仪表盘和仪表盘;与python段落中我的密码中voynich单词相关的点总数

a)这是密码:

Valid XHTML

2)接下来,数据库查看Voynich.accdb中的这些破折号和圆点条目,并从其access数据库中输出1000个甚至数百万个意大利语单词的不同叙述中的10个

3)然后我会仔细检查我认为最有意义的一个,然后出版或录制

有人能帮我吗?天使

最大的问题是,下面的代码是否可以进行一些调整

#**********************************************************************
# FILENAME :    CallSPEditRecord.py
#
# DESCRIPTION :
#               Illustrates using a stored procedure to perform several
#               actions relating to editing records within a table.
#
#               Calls a stored procedure as follows:
#
#       {CALL pyEdit_Record (?, ? ?, ?, ?, ?)}
#
#               With parameter :
#                   1 -   action (SELECT,UPDATE,INSERT,DELETE or ALL)
#                   2 -   current record ID
#                         Used if action is Select, Update or Delete)
#                   3 - 6 parameters for firstname, lastname, address, 
coty
#                         Used if action is Insert or Update
#
# ODBC USAGE :
#
#       Uses the notion of current Person ID as current record
#       (a value of -1 indicates none). Based on current record and
#       action, the program loops, executing the stored procedure to
#       either Select a specific record, Select all records, Update
#       or Delete the current record or Insert a new one.
#
#               Connects to Data Source using Data Source Name
#               Creates cursor on the connection
#               Drops and recreates a procedure 'pyEdit_Record'
#               Prompts user for either a record number or an action.
#               Actions available depend on whether a 'current' record
#               exists. Select One, Update and Delete need a current 
record ID
#               whereas Selecting all records and Insert don't.
#
import pyodbc

# Current record variables
currPID=-1
currFirstName=""
currLastName=""
currAddress=""
currCity=""

# List of actions
SEL=0           # action SELECT ONE
UPD=1           # action UPDATE
INS=2           # action INSERT
DEL=3           # action DELETE
ALL=4           # action SELECT ALL

#
# FUNCTION: getAction(currPID)
# Based on whether a current record is available, get next action to
# execute via stored procedure
# Returns two values, the action selected and a record ID to use as
# the current record id.
#
def getAction (currPID):

# Default action select
action=SEL

# Get PersonId to look up
print "\nNext Action: QUIT(0)\nSELECT (Rec No), SELECT ALL (A), INSERT 
(I),",
if currPID!=-1:
    print "UPDATE (U), DELETE (D)",

next=raw_input(" ? : ")

# Check to see if we have a number or a letter
try:
    PID=int(next)

    if PID==0:
        quit()
    action=0
except ValueError:
    PID=0
    next=next.upper()
    if next == "A":
        action=4

    elif next == "I":
        action=2

    elif next == "U":
        PID=currPID
        action=1

    elif next == "D":
        PID=currPID
        action=3
    else:
        exit()

return (action, PID)

#
# FUNCTION: printRec(rec)
# Function to display the contents of a record retrieved by 
cursor.fetchone()
# or cursor.fetchall()
#
def printRec (rec):

print "\nPersonID   : ", rec[0]

print "First Name : ",          # Comma on end stops new line being 
output
if rec[1]!=None:                # None appears for empty column
    print rec[1][0:10]          # Print string from 0 upto 10
else:
    print "-"                   # Print - for empty column

print "Last Name  : ",
if rec[2]!=None:
    print rec[2][0:10]
else:
    print "-"

print "Address    : ",
if rec[3]!=None:
    print rec[3][0:10]
else:
    print "-"

print "City       : ",
if rec[4]!=None:
    print rec[4][0:10]
else:
    print "-"

#
# Stored Procedure statements
#
# Create Stored Procedure 'pyEdit_Record' statement
#
sqlCreateSP="CREATE PROCEDURE pyEdit_Record (\
        @action int, @RecID int, \
        @pFirstName nvarchar(256), @pLastName nvarchar(256),\
        @pAddress nvarchar(256), @pCity nvarchar(256))\
        AS \
        IF (@action=0) BEGIN \
                SELECT PersonID, FirstName, LastName, Address, City \
                FROM TestTBL1 WHERE PersonID=@RecID; \
            END \
        ELSE \
            IF (@action=1) BEGIN \
                UPDATE TestTBL1 \
                SET FirstName=@pFirstName, LastName=@pLastName, \
                Address=@pAddress, City=@pCity \
                WHERE PersonID=@RecID; \
            END \
        ELSE \
            IF (@action=2) BEGIN \
                INSERT INTO TestTBL1 \
                (FirstName, LastName, Address, City) \
                VALUES (@pFirstName, @pLastName, @pAddress, @pCity);\
                SELECT @@IDENTITY; \
            END \
        ELSE \
            IF (@action=3) BEGIN \
                DELETE FROM TestTBL1 WHERE PersonID=@RecID; \
            END \
        ELSE \
            IF (@action=4) BEGIN \
                SELECT PersonID, FirstName, LastName, Address, City \
                FROM TestTBL1 ORDER BY PersonID; \
            END"
#
# Drop Stored Procedure statement
#
sqlDropSP="IF EXISTS (SELECT * FROM sys.objects \
       WHERE type='P' AND name='pyEdit_Record') \
       DROP PROCEDURE pyEdit_Record"
#
# Call Stored Procedure statement
# Parameters are action, recid, firstname, lastname, address, city
#
#    6 Parameters -- 1 - Action
#                    2 - Record ID
#                    3-6 READ - used in UPD and INS
#
#
sqlExecSP="{call pyEdit_Record (?,?,?,?,?,?)}"

# Connect to data source
conn=pyodbc.connect('DSN=DATASOURCE', autocommit=True) # either 
autocommit here

# Create cursor associated with connection
cursor=conn.cursor()

print "\nStored Procedure is : pyEdit_Record"

# Drop SP if exists
cursor.execute(sqlDropSP)

# Create SP using Create statement
cursor.execute(sqlCreateSP)

# Loop - prompt for next action. getAction() will call quit() if either
# blank or 0 entered
while currPID != 0:

#
# Returns action selected in next[0], and record ID in next[1]
#
next=getAction (currPID)
action=next[0]
currPID=next[1]

# If Select not chosen, it is either Update, Insert or Delete
# selected
if action!=SEL and action!=ALL:
    ok='Y'
    if action==UPD:
        # Updating current record
        print "\nPersonID  : ", currPID
        print "FirstName : ", currFirstName,
        currFirstName=raw_input("\nFirst Name : ")
        print "LastName  : ", currLastName,
        currLastName=raw_input("\nLast Name : ")
        print "Address   : ", currAddress,
        currAddress=raw_input("\nAddress : ")
        print "City      : ", currCity,
        currCity=raw_input("\nCity : ")

    elif action==INS:
        # Insert new record
        currFirstName=raw_input("\nFirst Name : ")
        currLastName=raw_input("Last Name  : ")
        currAddress=raw_input("Address    : ")
        currCity=raw_input("City       : ")

    elif action==DEL:
        # Delete current record
        print "\nDeleting record : ",currPID," confirm Y/N : ",
        ok=raw_input()
        ok=ok.upper()
        if ok!='Y':
            ok='N'

    # If OK to continue
    if ok=='Y':

        # Execute Stored Procedure for Update, Insert or Delete
        # and trap Error if raised
        try:
             cursor.execute(sqlExecSP,action,currPID,currFirstName,\
                            currLastName,currAddress,currCity)
        except pyodbc.Error, err:
            print 'Execute DML Error %s' % err

        # All OK. If Insert set new records as current record
        if action==INS:
            rec=cursor.fetchone()
            currPID=rec[0]
            print "\nNew Record is : ", currPID

        # If Delete current record is no longer available
        elif action==DEL:
            currPID=-1

        # If we have a current record, reselect and display
        if action==INS or action==UPD:
            action=SEL
            try:

cursor.execute(sqlExecSP,action,currPID,currFirstName, 
currLastName,currAddress,currCity)
            except pyodbc.Error, err:
                print 'Execute ReSelect Error %s' % err

            recs=cursor.fetchall()
            for rec in recs:
                printRec(rec)

else:
    #
    # Either select one or select all
    #
    # Clear variables
    currFirstName=""
    currLastName=""
    currAddress=""
    currCity=""

    # Action select one (using current record) or select all
    try:

cursor.execute(sqlExecSP,action,currPID,currFirstName,currLastName, 
currAddress,currCity)
    except pyodbc.Error, err:
        print 'Execute SELECT error %s' % err

    # Display results - one record if select one, many for select all
    recs=cursor.fetchall()
    for rec in recs:
        printRec(rec)

    if len(recs)==0:
        print ("\nNo matching records found")
        currPID=-1
    elif action==SEL:
        # If selected one record, it becomes the current record
        currFirstName=rec[1]
        currLastName=rec[2]
        currAddress=rec[3]
        currCity=rec[4]

    if action==ALL:
        # If selected all, we have no current record
        currPID=-1;

print ("\n\nComplete.")

# Close and delete cursor
cursor.close()
del cursor

# Close connection
conn.close()

Tags: orandtorawifactioncurrentrecord