Changeset cd552e in git


Ignore:
Timestamp:
Aug 12, 2019, 4:20:41 PM (4 years ago)
Author:
Murray Heymann <heymann.murray@…>
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
Message:
Create dir in home for cache files for ml
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • Singular/iparith.cc

    rb03e2f rcd552e  
    79487948        unsigned nCount = (sArithBase.nCmdUsed-1) / 3;
    79497949
    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();
    79557952
    79567953        if ((3*nCount) < sArithBase.nCmdUsed) {
  • machine_learning/extract.lib

    rb03e2f rcd552e  
    88list combined = delete(l, 1) + k;
    99
    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
     11for (i = 1; i < size(combined) + 1; i++) {
     12        print(combined[i]);
    1713}
    1814
  • machine_learning/ml_python/common/constants.py

    rb03e2f rcd552e  
    44import os
    55
    6 SINGULAR_BIN = "~/Singular/Singular4/bin/Singular"
     6HOME_DIR       = os.path.expanduser("~/.singular")
     7SINGULAR_BIN   = os.path.expanduser("~/Singular/Singular4/bin/Singular")
    78EXTRACT_SCRIPT = "extract.lib"
    8 KEYWORDS_FILE = "keywords.txt"
    9 VECTORS_NPY = ".vectors.npy"
    10 HELPFILE_NPY = ".helpfilelist.npy"
     9KEYWORDS_FILE  = os.path.expanduser("~/.singular/keywords.txt")
     10VECTORS_NPY    = os.path.expanduser("~/.singular/vectors.npy")
     11HELPFILE_NPY   = os.path.expanduser("~/.singular/helpfilelist.npy")
    1112
    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")
     13HELP_FILE_URL  = "ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/src/4-1-2/doc.tbz2"
     14HELP_FILE_PATH = os.path.join(os.path.expanduser("~/.singular"),
     15        "helpfiles", "singular")
  • machine_learning/ml_python/common/keyword_vector.py

    rb03e2f rcd552e  
    2020        print("Please provide a valid input file as argument to read "
    2121              "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
    2624
    2725
     
    4846        if not os.path.isfile(filename):
    4947            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
    5550    assert dictionary is not None, \
    5651            "Please provide a valid dictionary as argument"
  • machine_learning/ml_python/common/lookuptable.py

    rb03e2f rcd552e  
    1717from common.constants import HELP_FILE_URL, HELP_FILE_PATH, SINGULAR_BIN, \
    1818                        EXTRACT_SCRIPT, KEYWORDS_FILE, HELPFILE_NPY, \
    19                         VECTORS_NPY
     19                        VECTORS_NPY, HOME_DIR
    2020
    2121
     
    5050    'keywords.txt'
    5151    """
     52    # ensure the homedir exists
     53    if not os.path.isdir(HOME_DIR):
     54        os.makedirs(HOME_DIR)
     55
    5256    # 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)
    5459
    5560    # read from the file created by singular
    5661    dictionary = read_dictionary()
    57 
    58     # sort alphabetically
    59     dictionary = np.sort(np.unique(dictionary))
    60 
    61     # write back to the same file
    62     with open(KEYWORDS_FILE, "w") as file:
    63         for word in dictionary:
    64             file.write(word + "\n")
    6562
    6663    return dictionary
     
    7168    Get a list of helpfiles, and generate a word occurance vector for each.
    7269    """
     70
    7371    if dictionary is None:
    7472        dictionary = read_dictionary(KEYWORDS_FILE)
     
    7876            not os.path.isfile(HELPFILE_NPY) or \
    7977            not attempt_cached:
     78        os.makedirs(HOME_DIR, exist_ok=True)
    8079        file_list = np.array(get_list_of_htm_files())
    8180        np.save(HELPFILE_NPY, file_list)
     
    101100    check whether the various files exist, and create if necessary.
    102101    """
     102    if not os.path.isdir(HOME_DIR):
     103        os.makedirs(HOME_DIR)
     104
    103105    # check for and download help files if necessary
    104106    tbz2_path = os.path.join(HELP_FILE_PATH, "helpfiles.tbz2")
     
    111113    else:
    112114        dictionary = None
    113 
    114115
    115116    if not os.path.isfile(VECTORS_NPY) or not os.path.isfile(HELPFILE_NPY):
     
    128129    if not os.path.isfile(KEYWORDS_FILE):
    129130        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):
    131134        retvalue = False
    132135
  • machine_learning/ml_python/tests/common/test_keyword_vectors.py

    rb03e2f rcd552e  
    1515        print("Non-existant file")
    1616        if sys.version_info[0] == 3:
    17             self.assertRaises(FileNotFoundError,
     17            #self.assertRaises(FileNotFoundError,
     18            self.assertRaises(IOError,
    1819                              read_dictionary,
    1920                              "asdfasdf")
     
    3839        print("Test non-existant file")
    3940        if sys.version_info[0] == 3:
    40             self.assertRaises(FileNotFoundError,
     41            #self.assertRaises(FileNotFoundError,
     42            self.assertRaises(IOError,
    4143                              count_occurances,
    4244                              "asdfasdf",
  • machine_learning/ml_python/tests/common/test_lookuptable.py

    rb03e2f rcd552e  
    66from common.lookuptable import *
    77from common.keyword_vector import count_occurances
    8 from common.constants import KEYWORDS_FILE, VECTORS_NPY, HELP_FILE_PATH
     8from common.constants import KEYWORDS_FILE, VECTORS_NPY, HELP_FILE_PATH, \
     9        HOME_DIR
    910
    1011class TestLookuptableMethods(unittest.TestCase):
     
    1314        os.system("rm -r " + HELP_FILE_PATH)
    1415        fetch_tbz2_data()
    15         fetch_tbz2_data()
    1616        files = get_list_of_htm_files()
    1717        self.assertGreater(len(files), 0)
    1818
    1919    def test_extract_keywords(self):
    20         extract_keywords()
     20        #extract_keywords()
    2121        self.assertTrue(os.path.isfile(KEYWORDS_FILE))
    2222
     
    3535    def test_init_table_on_system(self):
    3636        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)
    4038
    4139        init_table_on_system()
     
    6664
    6765if __name__ == '__main__':
     66    if os.path.isdir(HOME_DIR):
     67        os.system("rm -r " + HOME_DIR)
     68    extract_keywords()
     69    fetch_tbz2_data()
    6870    #cProfile.run("unittest.main()")
    6971    unittest.main()
  • machine_learning/mlpredict.c

    rb03e2f rcd552e  
    88#include <stdio.h>
    99#include <Python.h>
     10
     11#include "mlpredict.h"
    1012
    1113/* Locally defined macros */
     
    107109
    108110/**
    109  * A wrapper for Py_Finalize, checking whether it is necessary in the first
    110  * place.
     111 * Tell python to decrement the global variables, checking whether it is
     112 * necessary in the first place.
    111113 *
    112114 * @return An integer: 1 if successful, 0 if not.
     
    116118        int retvalue = 1;
    117119
    118         Py_XDECREF(pDictionary);
    119         Py_XDECREF(pVectors);
    120         Py_XDECREF(pFile_list);
    121 
    122120        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(); */
    125130        } else {
    126131                retvalue = 0;
  • machine_learning/mlpredict.h

    rb03e2f rcd552e  
    88#ifndef MLPREDICT_H
    99#define MLPREDICT_H
     10
     11#ifdef __cplusplus
    1012extern "C" {
     13#endif /* ifdef cpp */
    1114
    1215/**
     
    2932
    3033/**
    31  * Finalize the python interpreter
     34 * Tell python to decrement the global variables, checking whether it is
     35 * necessary in the first place.
    3236 *
    3337 * @return An integer: 1 if successful, 0 if not.
     
    5458                                           int *pred_len);
    5559
     60#ifdef __cplusplus
    5661}
    57 #endif
     62#endif /* ifdef cpp */
     63#endif
Note: See TracChangeset for help on using the changeset viewer.