#!/usr/bin/env python3 ####################################################################### # map our sw collection to frequency lists # # Author: Garry Morrison # Date: 2015-03-25 # Update: # Copyright: closed for now # # Usage: ./play_with_sw_to_freq.py # ####################################################################### import sys import glob import os from the_semantic_db_code import * from the_semantic_db_functions import * from the_semantic_db_processor import * C = context_list("sw files to frequency lists") # the .sw directory: sw_file_dir = "sw-examples" # check it exists: if not os.path.exists(sw_file_dir): print(sw_file_dir + " not found. Exiting ...") sys.exit(0) # NB: we need "dir\file" instead of "dir/file" for our "file != dest_file" line to work. dest_file = "sw-examples\sw-files-to-frequency-lists.sw" size_threshold = 10000 # start with 10K for file in glob.glob(sw_file_dir + "/*.sw"): if file != dest_file: size = os.path.getsize(file) if size <= size_threshold: # only work with small files for now. working_context = context_list("") # reset the context_list for each file # print("file:",file) base = os.path.basename(file) print("loading sw file:",base) x = ket("sw file: " + base) print("x:",x) load_sw(working_context,file) C.learn("kets",x,working_context.multiverse_to_freq_list()) # code to save the results: save_sw(C,dest_file)