Changeset cd552e in git
- Timestamp:
- Aug 12, 2019, 4:20:41 PM (4 years ago)
- Branches:
- (u'spielwiese', 'd1ba061a762c62d3a25159d8da8b6e17332291fa')
- Children:
- 87d423b777b7762ac55fd9308018f3d7a12b9940
- Parents:
- b03e2f1e6cf3ff16ea956608cf7b560430904959
- git-author:
- Murray Heymann <heymann.murray@gmail.com>2019-08-12 16:20:41+02:00
- git-committer:
- Murray Heymann <heymann.murray@gmail.com>2019-08-12 16:20:52+02:00
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/iparith.cc
rb03e2f rcd552e 7948 7948 unsigned nCount = (sArithBase.nCmdUsed-1) / 3; 7949 7949 7950 if (ml_is_initialised()) { 7951 printf("ml is initialised\n"); 7952 } else { 7953 printf("ml is NOT initialised\n"); 7954 } 7950 ml_initialise(); 7951 ml_finalise(); 7955 7952 7956 7953 if ((3*nCount) < sArithBase.nCmdUsed) { -
machine_learning/extract.lib
rb03e2f rcd552e 8 8 list combined = delete(l, 1) + k; 9 9 10 // create file, overwrite if exists 11 write(":w keywords.txt", combined[1]); 12 13 14 // write remaining entries to file 15 for (i = 2; i < size(combined) + 1; i++) { 16 write(":a keywords.txt", combined[i]); 10 // printentries to STDOUT 11 for (i = 1; i < size(combined) + 1; i++) { 12 print(combined[i]); 17 13 } 18 14 -
machine_learning/ml_python/common/constants.py
rb03e2f rcd552e 4 4 import os 5 5 6 SINGULAR_BIN = "~/Singular/Singular4/bin/Singular" 6 HOME_DIR = os.path.expanduser("~/.singular") 7 SINGULAR_BIN = os.path.expanduser("~/Singular/Singular4/bin/Singular") 7 8 EXTRACT_SCRIPT = "extract.lib" 8 KEYWORDS_FILE = "keywords.txt"9 VECTORS_NPY = ".vectors.npy"10 HELPFILE_NPY = ".helpfilelist.npy"9 KEYWORDS_FILE = os.path.expanduser("~/.singular/keywords.txt") 10 VECTORS_NPY = os.path.expanduser("~/.singular/vectors.npy") 11 HELPFILE_NPY = os.path.expanduser("~/.singular/helpfilelist.npy") 11 12 12 HELP_FILE_URL = "ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/src/4-1-2/doc.tbz2" 13 HELP_FILE_PATH = os.path.join("helpfiles", "singular") 13 HELP_FILE_URL = "ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/src/4-1-2/doc.tbz2" 14 HELP_FILE_PATH = os.path.join(os.path.expanduser("~/.singular"), 15 "helpfiles", "singular") -
machine_learning/ml_python/common/keyword_vector.py
rb03e2f rcd552e 20 20 print("Please provide a valid input file as argument to read " 21 21 "dictionary") 22 if sys.version_info[0] == 3: # pylint: disable=no-else-raise 23 raise FileNotFoundError 24 else: 25 raise IOError 22 print(filename) 23 raise IOError 26 24 27 25 … … 48 46 if not os.path.isfile(filename): 49 47 print("Please provide a valid input file as argument") 50 if sys.version_info[0] == 3: # pylint: disable=no-else-raise 51 raise FileNotFoundError 52 else: 53 print(filename) 54 raise IOError 48 print(filename) 49 raise IOError 55 50 assert dictionary is not None, \ 56 51 "Please provide a valid dictionary as argument" -
machine_learning/ml_python/common/lookuptable.py
rb03e2f rcd552e 17 17 from common.constants import HELP_FILE_URL, HELP_FILE_PATH, SINGULAR_BIN, \ 18 18 EXTRACT_SCRIPT, KEYWORDS_FILE, HELPFILE_NPY, \ 19 VECTORS_NPY 19 VECTORS_NPY, HOME_DIR 20 20 21 21 … … 50 50 'keywords.txt' 51 51 """ 52 # ensure the homedir exists 53 if not os.path.isdir(HOME_DIR): 54 os.makedirs(HOME_DIR) 55 52 56 # extract keywords using the singular script 53 os.system(SINGULAR_BIN + " " + EXTRACT_SCRIPT) 57 os.system(SINGULAR_BIN + " -q " + EXTRACT_SCRIPT + 58 " | sort | uniq > " + KEYWORDS_FILE) 54 59 55 60 # read from the file created by singular 56 61 dictionary = read_dictionary() 57 58 # sort alphabetically59 dictionary = np.sort(np.unique(dictionary))60 61 # write back to the same file62 with open(KEYWORDS_FILE, "w") as file:63 for word in dictionary:64 file.write(word + "\n")65 62 66 63 return dictionary … … 71 68 Get a list of helpfiles, and generate a word occurance vector for each. 72 69 """ 70 73 71 if dictionary is None: 74 72 dictionary = read_dictionary(KEYWORDS_FILE) … … 78 76 not os.path.isfile(HELPFILE_NPY) or \ 79 77 not attempt_cached: 78 os.makedirs(HOME_DIR, exist_ok=True) 80 79 file_list = np.array(get_list_of_htm_files()) 81 80 np.save(HELPFILE_NPY, file_list) … … 101 100 check whether the various files exist, and create if necessary. 102 101 """ 102 if not os.path.isdir(HOME_DIR): 103 os.makedirs(HOME_DIR) 104 103 105 # check for and download help files if necessary 104 106 tbz2_path = os.path.join(HELP_FILE_PATH, "helpfiles.tbz2") … … 111 113 else: 112 114 dictionary = None 113 114 115 115 116 if not os.path.isfile(VECTORS_NPY) or not os.path.isfile(HELPFILE_NPY): … … 128 129 if not os.path.isfile(KEYWORDS_FILE): 129 130 retvalue = False 130 if not os.path.isfile(VECTORS_NPY) or not os.path.isfile(HELPFILE_NPY): 131 if not os.path.isdir(HOME_DIR) or \ 132 not os.path.isfile(VECTORS_NPY) or \ 133 not os.path.isfile(HELPFILE_NPY): 131 134 retvalue = False 132 135 -
machine_learning/ml_python/tests/common/test_keyword_vectors.py
rb03e2f rcd552e 15 15 print("Non-existant file") 16 16 if sys.version_info[0] == 3: 17 self.assertRaises(FileNotFoundError, 17 #self.assertRaises(FileNotFoundError, 18 self.assertRaises(IOError, 18 19 read_dictionary, 19 20 "asdfasdf") … … 38 39 print("Test non-existant file") 39 40 if sys.version_info[0] == 3: 40 self.assertRaises(FileNotFoundError, 41 #self.assertRaises(FileNotFoundError, 42 self.assertRaises(IOError, 41 43 count_occurances, 42 44 "asdfasdf", -
machine_learning/ml_python/tests/common/test_lookuptable.py
rb03e2f rcd552e 6 6 from common.lookuptable import * 7 7 from common.keyword_vector import count_occurances 8 from common.constants import KEYWORDS_FILE, VECTORS_NPY, HELP_FILE_PATH 8 from common.constants import KEYWORDS_FILE, VECTORS_NPY, HELP_FILE_PATH, \ 9 HOME_DIR 9 10 10 11 class TestLookuptableMethods(unittest.TestCase): … … 13 14 os.system("rm -r " + HELP_FILE_PATH) 14 15 fetch_tbz2_data() 15 fetch_tbz2_data()16 16 files = get_list_of_htm_files() 17 17 self.assertGreater(len(files), 0) 18 18 19 19 def test_extract_keywords(self): 20 extract_keywords()20 #extract_keywords() 21 21 self.assertTrue(os.path.isfile(KEYWORDS_FILE)) 22 22 … … 35 35 def test_init_table_on_system(self): 36 36 tbz2_path = os.path.join(HELP_FILE_PATH, "helpfiles.tbz2") 37 os.remove(tbz2_path) 38 os.remove(KEYWORDS_FILE) 39 os.remove(VECTORS_NPY) 37 os.system("rm -r " + HOME_DIR) 40 38 41 39 init_table_on_system() … … 66 64 67 65 if __name__ == '__main__': 66 if os.path.isdir(HOME_DIR): 67 os.system("rm -r " + HOME_DIR) 68 extract_keywords() 69 fetch_tbz2_data() 68 70 #cProfile.run("unittest.main()") 69 71 unittest.main() -
machine_learning/mlpredict.c
rb03e2f rcd552e 8 8 #include <stdio.h> 9 9 #include <Python.h> 10 11 #include "mlpredict.h" 10 12 11 13 /* Locally defined macros */ … … 107 109 108 110 /** 109 * A wrapper for Py_Finalize, checking whether it is necessary in the first110 * place.111 * Tell python to decrement the global variables, checking whether it is 112 * necessary in the first place. 111 113 * 112 114 * @return An integer: 1 if successful, 0 if not. … … 116 118 int retvalue = 1; 117 119 118 Py_XDECREF(pDictionary);119 Py_XDECREF(pVectors);120 Py_XDECREF(pFile_list);121 122 120 if (Py_IsInitialized()) { 123 Py_Finalize(); 124 retvalue = 1; 121 Py_XDECREF(pDictionary); 122 Py_XDECREF(pVectors); 123 Py_XDECREF(pFile_list); 124 pDictionary = NULL; 125 pVectors = NULL; 126 pFile_list = NULL; 127 128 /* this breaks libpython2.7.so, so leave out: */ 129 /* Py_Finalize(); */ 125 130 } else { 126 131 retvalue = 0; -
machine_learning/mlpredict.h
rb03e2f rcd552e 8 8 #ifndef MLPREDICT_H 9 9 #define MLPREDICT_H 10 11 #ifdef __cplusplus 10 12 extern "C" { 13 #endif /* ifdef cpp */ 11 14 12 15 /** … … 29 32 30 33 /** 31 * Finalize the python interpreter 34 * Tell python to decrement the global variables, checking whether it is 35 * necessary in the first place. 32 36 * 33 37 * @return An integer: 1 if successful, 0 if not. … … 54 58 int *pred_len); 55 59 60 #ifdef __cplusplus 56 61 } 57 #endif 62 #endif /* ifdef cpp */ 63 #endif
Note: See TracChangeset
for help on using the changeset viewer.