How to connect sqlite database to weka - sqlite
I'm trying to import a database from sqlite3 to weka, but the problem is that even after the database is loaded and displayed, when I click ok so I can start working with the database, the message "couldn't read from database: unknown data type: text " appears. I've tried modifying the DatabaseUtil.props file but nothing seems to work, so I really apreacite if someone could tell me how to solve this issue. Thanks
I have read these instructions:
https://waikato.github.io/weka-wiki/databases/#configuration-files
Now this is my DatabaseUtils.props file, please change the jdbcURL entry
# Database settings for sqlite 3.x
#
# General information on database access can be found here:
# https://waikato.github.io/weka-wiki/databases
#
# url: http://www.sqlite.org/
# jdbc: http://www.zentus.com/sqlitejdbc/
# author: Fracpete (fracpete at waikato dot ac dot nz)
# version: $Revision: 5836 $
# JDBC driver (comma-separated list)
jdbcDriver=org.sqlite.JDBC,
# database URL
jdbcURL=jdbc:sqlite:/some/path/to/mydb.sqlite
# specific data types
# string, getString() = 0; --> nominal
# boolean, getBoolean() = 1; --> nominal
# double, getDouble() = 2; --> numeric
# byte, getByte() = 3; --> numeric
# short, getByte()= 4; --> numeric
# int, getInteger() = 5; --> numeric
# long, getLong() = 6; --> numeric
# float, getFloat() = 7; --> numeric
# date, getDate() = 8; --> date
# text, getString() = 9; --> string
# time, getTime() = 10; --> date
#SQLITE DATATYPES
#NULL. The value is a NULL value.
null=9
#INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
integer=5
#REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
float=6
#TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
TEXT=9
text=9
#BLOB. The value is a blob of data, stored exactly as it was input.
# other options
CREATE_DOUBLE=DOUBLE
CREATE_STRING=varchar(2000)
CREATE_STRING=TEXT
CREATE_INT=INT
CREATE_DATE=DATETIME
DateFormat=yyyy-MM-dd HH:mm:ss
checkUpperCaseNames=false
checkLowerCaseNames=false
checkForTable=true
# All the reserved keywords for this database
# Based on the keywords listed at the following URL (2009-04-13):
# http://www.sqlite.org/lang_keywords.html
Keywords=\
ABORT,\
ADD,\
AFTER,\
ALL,\
ALTER,\
ANALYZE,\
AND,\
AS,\
ASC,\
ATTACH,\
AUTOINCREMENT,\
BEFORE,\
BEGIN,\
BETWEEN,\
BY,\
CASCADE,\
CASE,\
CAST,\
CHECK,\
COLLATE,\
COLUMN,\
COMMIT,\
CONFLICT,\
CONSTRAINT,\
CREATE,\
CROSS,\
CURRENT_DATE,\
CURRENT_TIME,\
CURRENT_TIMESTAMP,\
DATABASE,\
DEFAULT,\
DEFERRABLE,\
DEFERRED,\
DELETE,\
DESC,\
DETACH,\
DISTINCT,\
DROP,\
EACH,\
ELSE,\
END,\
ESCAPE,\
EXCEPT,\
EXCLUSIVE,\
EXISTS,\
EXPLAIN,\
FAIL,\
FOR,\
FOREIGN,\
FROM,\
FULL,\
GLOB,\
GROUP,\
HAVING,\
IF,\
IGNORE,\
IMMEDIATE,\
IN,\
INDEX,\
INDEXED,\
INITIALLY,\
INNER,\
INSERT,\
INSTEAD,\
INTERSECT,\
INTO,\
IS,\
ISNULL,\
JOIN,\
KEY,\
LEFT,\
LIKE,\
LIMIT,\
MATCH,\
NATURAL,\
NOT,\
NOTNULL,\
NULL,\
OF,\
OFFSET,\
ON,\
OR,\
ORDER,\
OUTER,\
PLAN,\
PRAGMA,\
PRIMARY,\
QUERY,\
RAISE,\
REFERENCES,\
REGEXP,\
REINDEX,\
RELEASE,\
RENAME,\
REPLACE,\
RESTRICT,\
RIGHT,\
ROLLBACK,\
ROW,\
SAVEPOINT,\
SELECT,\
SET,\
TABLE,\
TEMP,\
TEMPORARY,\
THEN,\
TO,\
TRANSACTION,\
TRIGGER,\
UNION,\
UNIQUE,\
UPDATE,\
USING,\
VACUUM,\
VALUES,\
VIEW,\
VIRTUAL,\
WHEN,\
WHERE
# The character to append to attribute names to avoid exceptions due to
# clashes between keywords and attribute names
KeywordsMaskChar=_
#flags for loading and saving instances using DatabaseLoader/Saver
nominalToStringLimit=50
idColumn=auto_generated_id
Try putting the DatabaseUtils.prop file in the Weka home directory. Also, in the file you should add sth like TEXT=0 or TEXT=9 in the corresponding sector.
Related
Having Trouble converting a string to bytes
I'm trying to convert a string to a byte, thats what I've done. I want to send out a Modbusprotocol via serial and put it together in bitstring: tiger = '01' read = '03' ac_val = '0031' word = '0002' code = tiger+read+ac_val+word print(code) 010300310002 #now i want to put thist string in a bitstring with the function: codeh = bytes.fromhex(code) codeh = b'\x01\x03\x001\x00\x02 #This is what i got But i was expecting: codeh = b'\x01\x03\x00\x31\x00\x02 I have no idea why the output is like this.
What it's showing in the output is the ASCII representation of the byte values. Hex 31 corresponds to the ascii character '1'. Try this to see a demonstration: bytes.fromhex('415343494921') Here's a chart that shows these low values: https://en.wikipedia.org/wiki/ASCII#Control_code_chart
The encryption won't decrypt
I was given an encrypted copy of the study guide here, but how do you decrypt and read it??? In a file called pa11.py write a method called decode(inputfile,outputfile). Decode should take two parameters - both of which are strings. The first should be the name of an encoded file (either helloworld.txt or superdupertopsecretstudyguide.txt or yet another file that I might use to test your code). The second should be the name of a file that you will use as an output file. Your method should read in the contents of the inputfile and, using the scheme described in the hints.txt file above, decode the hidden message, writing to the outputfile as it goes (or all at once when it is done depending on what you decide to use). The penny math lecture is here. """ Program: pennyMath.py Author: CS 1510 Description: Calculates the penny math value of a string. """ # Get the input string original = input("Enter a string to get its cost in penny math: ") cost = 0 Go through each character in the input string for char in original: value = ord(char) #ord() gives us the encoded number! if char>="a" and char<="z": cost = cost+(value-96) #offset the value of ord by 96 elif char>="A" and char<="Z": cost = cost+(value-64) #offset the value of ord by 64 print("The cost of",original,"is",cost) Another hint: Don't forget about while loops... Another hint: After letters - skip ahead by their pennymath value positions + 2 After numbers - skip ahead by their number + 7 positions After anything else - just skip ahead by 1 position The issue I'm having in that I cant seem to get the coding right to decode the file it comes out looking the same. This is the current code I have been using. But once I try to decrypt the message it stays the same. def pennycost(c): if c >="a" and c <="z": return ord(c)-96 elif c>="A" and c<="Z": return ord(c)-64 def decryption(inputfile,outputfile): with open(inputfile) as f: fo = open(outputfile,"w") count = 0 while True: c = f.read(1) if not c: break; if count > 0: count = count -1; continue elif c.isalpha(): count = pennycost(c) fo.write(c) elif c.isdigit(): count = int(c) fo.write(c) else: count = 6 fo.write(c) fo.close() inputfile = input("Please enter the input file name: ") outputfile = input("Plese enter the output file name(EXISTING FILE WILL BE OVER WRITTEN!): ") decryption(inputfile,outputfile)
How to display WebDynpro ABAP in ABAP report?
I've just started coding ABAP for a few days and I have a task to call the report from transaction SE38 and have the report's result shown on the screen of the WebDynPro application SE80. The report take the user input ( e.g: Material Number, Material Type, Plant, Sale Org. ) as a condition for querying, so the WebDynPro application must allow user to key in this parameters. In some related article they were talking about using SUBMIT rep EXPORTING LIST TO MEMORY and CALL FUNCTION 'LIST_FROM_MEMORY' but so far I really have no idea to implement it. Any answers will be appreciated. Thanks!
You can export it to PDF. Therefore, when a user clicks on a link, you run the conversion and display the file in the browser window. To do so, you start by creating a JOB using the following code below: constants c_name type tbtcjob-jobname value 'YOUR_JOB_NAME'. data v_number type tbtcjob-jobcount. data v_print_parameters type pri_params. call function 'JOB_OPEN' exporting jobname = c_name importing jobcount = v_number exceptions cant_create_job = 1 invalid_job_data = 2 jobname_missing = 3 others = 4. if sy-subrc = 0. commit work and wait. else. EXIT. "// todo: err handling here endif. Then, you need to get the printer parameters in order to submit the report: call function 'GET_PRINT_PARAMETERS' exporting destination = 'LP01' immediately = space new_list_id = 'X' no_dialog = 'X' user = sy-uname importing out_parameters = v_print_parameters exceptions archive_info_not_found = 1 invalid_print_params = 2 invalid_archive_params = 3 others = 4. v_print_parameters-linct = 55. v_print_parameters-linsz = 1. v_print_parameters-paart = 'LETTER'. Now you submit your report using the filters that apply. Do not forget to add the job parameters to it, as the code below shows: submit your_report_name to sap-spool spool parameters v_print_parameters without spool dynpro with ...(insert all your filters here) via job c_name number v_number and return. if sy-subrc = 0. commit work and wait. else. EXIT. "// todo: err handling here endif. After that, you close the job: call function 'JOB_CLOSE' exporting jobcount = v_number jobname = c_name strtimmed = 'X' exceptions cant_start_immediate = 1 invalid_startdate = 2 jobname_missing = 3 job_close_failed = 4 job_nosteps = 5 job_notex = 6 lock_failed = 7 others = 8. if sy-subrc = 0. commit work and wait. else. EXIT. "// todo: err handling here endif. Now the job will proceed and you'll need to wait for it to complete. Do it with a loop. Once the job is completed, you can get it's spool output and convert to PDF. data v_rqident type tsp01-rqident. data v_job_head type tbtcjob. data t_job_steplist type tbtcstep occurs 0 with header line. data t_pdf like tline occurs 0 with header line. do 200 times. wait up to 1 seconds. call function 'BP_JOB_READ' exporting job_read_jobcount = v_number job_read_jobname = c_name job_read_opcode = '20' importing job_read_jobhead = v_job_head tables job_read_steplist = t_job_steplist exceptions invalid_opcode = 1 job_doesnt_exist = 2 job_doesnt_have_steps = 3 others = 4. read table t_job_steplist index 1. if not t_job_steplist-listident is initial. v_rqident = t_job_steplist-listident. exit. else. clear v_job_head. clear t_job_steplist. clear t_job_steplist[]. endif. enddo. check not v_rqident is initial. call function 'CONVERT_ABAPSPOOLJOB_2_PDF' exporting src_spoolid = v_rqident dst_device = 'LP01' tables pdf = t_pdf exceptions err_no_abap_spooljob = 1 err_no_spooljob = 2 err_no_permission = 3 err_conv_not_possible = 4 err_bad_destdevice = 5 user_cancelled = 6 err_spoolerror = 7 err_temseerror = 8 err_btcjob_open_failed = 9 err_btcjob_submit_failed = 10 err_btcjob_close_failed = 11 others = 12. If you're going to send it via HTTP, you may need to convert it to BASE64 as well. field-symbols <xchar> type x. data v_offset(10) type n. data v_char type c. data v_xchar(2) type x. data v_xstringdata_aux type xstring. data v_xstringdata type xstring. data v_base64data type string. data v_base64data_aux type string. loop at t_pdf. do 134 times. v_offset = sy-index - 1. v_char = t_pdf+v_offset(1). assign v_char to <xchar> casting type x. concatenate v_xstringdata_aux <xchar> into v_xstringdata_aux in byte mode. enddo. concatenate v_xstringdata v_xstringdata_aux into v_xstringdata in byte mode. clear v_xstringdata_aux. endloop. call function 'SCMS_BASE64_ENCODE_STR' exporting input = v_xstringdata importing output = v_base64data. v_base64data_aux = v_base64data. while strlen( v_base64data_aux ) gt 255. clear t_base64data. t_base64data-data = v_base64data_aux. v_base64data_aux = v_base64data_aux+255. append t_base64data. endwhile. if not v_base64data_aux is initial. t_base64data-data = v_base64data_aux. append t_base64data. endif. And you're done! Hope it helps.
As previous speakers said, you should do extensive training before implementing such stuff in productive environment. However, calling WebdynPro ABAP within report can be done with the help of WDY_EXECUTE_IN_PLACE function module. You should pass there Webdyn Pro application and necessary parameters. CALL FUNCTION 'WDY_EXECUTE_IN_PLACE' EXPORTING * PROTOCOL = INTERNALMODE = ' ' * SMARTCLIENT = APPLICATION = 'Z_MY_WEBDYNPRO' * CONTAINER_NAME = PARAMETERS = lt_parameters SUPPRESS_OUTPUT = TRY_TO_USE_SAPGUI_THEME = ' ' IMPORTING OUT_URL = ex_url . IF sy-subrc <> 0. * Implement suitable error handling here ENDIF.
IndexError: list index out of range, scores.append( (fields[0], fields[1]))
I'm trying to read a file and put contents in a list. I have done this mnay times before and it has worked but this time it throws back the error "list index out of range". the code is: with open("File.txt") as f: scores = [] for line in f: fields = line.split() scores.append( (fields[0], fields[1])) print(scores) The text file is in the format; Alpha:[0, 1] Bravo:[0, 0] Charlie:[60, 8, 901] Foxtrot:[0] I cant see why it is giving me this problem. Is it because I have more than one value for each item? Or is it the fact that I have a colon in my text file? How can I get around this problem? Thanks
If I understand you well this code will print you desired result: import re with open("File.txt") as f: # Let's make dictionary for scores {name:scores}. scores = {} # Define regular expressin to parse team name and team scores from line. patternScore = '\[([^\]]+)\]' patternName = '(.*):' for line in f: # Find value for team name and its scores. fields = re.search(patternScore, line).groups()[0].split(', ') name = re.search(patternName, line).groups()[0] # Update dictionary with new value. scores[name] = fields # Print output first goes first element of keyValue in dict then goes keyName for key in scores: print (scores[key][0] + ':' + key) You will recieve following output: 60:Charlie 0:Alpha 0:Bravo 0:Foxtrot
Pyparsing - name not starting with a character
I am trying to use Pyparsing to identify a keyword which is not beginning with $ So for the following input: $abc = 5 # is not a valid one abc123 = 10 # is valid one abc$ = 23 # is a valid one I tried the following var = Word(printables, excludeChars='$') var.parseString('$abc') But this doesn't allow any $ in var. How can I specify all printable characters other than $ in the first character position? Any help will be appreciated. Thanks Abhijit
You can use the method I used to define "all characters except X" before I added the excludeChars parameter to the Word class: NOT_DOLLAR_SIGN = ''.join(c for c in printables if c != '$') keyword_not_starting_with_dollar = Word(NOT_DOLLAR_SIGN, printables) This should be a bit more efficient than building up with a Combine and a NotAny. But this will match almost anything, integers, words, valid identifiers, invalid identifiers, so I'm skeptical of the value of this kind of expression in your parser.