# Path: tensorlog/dataset.py
# class Dataset(object):
#     def __init__(self,xDict,yDict):
#     def isSinglePredicate(self):
#     def extractMode(self,mode):
#     def modesToLearn(self):
#     def hasMode(self,mode):
#     def getX(self,mode):
#     def getY(self,mode):
#     def size(self):
#     def shuffle(self):
#     def minibatchIterator(self,batchSize=100,shuffleFirst=True):
#     def pprint(self):
#     def serialize(self,dir):
#     def deserialize(dir):
#     def uncacheExamples(dsetFile,db,exampleFile,proppr=True):
#     def uncacheMatrix(dsetFile,db,functorToLearn,functorInDB):
#     def loadMatrix(db,functorToLearn,functorInDB):
#     def _parseLine(line,proppr=True):
#     def loadProPPRExamples(db,fileName):
#     def loadExamples(db,fileName,proppr=False):
#         def getId(typeName,symbol):
#     def saveProPPRExamples(self,fileName,db,append=False,mode=None):
# 
# Path: tensorlog/matrixdb.py
# NULL_ENTITY_NAME = dbschema.NULL_ENTITY_NAME
# THING = dbschema.THING
# OOV_ENTITY_NAME = dbschema.OOV_ENTITY_NAME
# TRAINABLE_DECLARATION_FUNCTOR = 'trainable'
# class MatrixDB(object):
#   def __init__(self,initSchema=None):
#   def checkTyping(self):
#   def isTypeless(self):
#   def _fillDefault(self,typeName):
#   def dim(self,typeName=None):
#   def onehot(self,s,typeName=None,outOfVocabularySymbolsAllowed=False):
#   def zeros(self,numRows=1,typeName=None):
#   def ones(self,typeName=None):
#   def nullMatrix(self,numRows=1,typeName=None,numCols=0):
#   def transposeNeeded(mode,transpose=False):
#   def matrix(self,mode,transpose=False):
#   def vector(self,mode):
#   def matrixPreimage(self,mode):
#   def matrixPreimageMat(self,mode):
#   def matrixPreimageOnesType(self,mode):
#   def matrixPreimageOnes(self,mode):
#   def isParameter(self,mode):
#   def markAsParam(self,functor,arity):
#   def markAsParameter(self,functor,arity):
#   def clearParameterMarkings(self):
#   def getParameter(self,functor,arity):
#   def parameterIsInitialized(self,functor,arity):
#   def setParameter(self,functor,arity,replacement):
#   def asSymbol(self,symbolId,typeName=None):
#   def asSymbolId(self,symbol,typeName=None):
#   def rowAsSymbolDict(self,row,typeName=None):
#   def arrayAsSymbolDict(self,arr,typeName=None):
#   def matrixAsSymbolDict(self,m,typeName=None):
#   def matrixAsPredicateFacts(self,functor,arity,m):
#   def inDB(self,functor,arity):
#   def summary(self,functor,arity):
#   def listing(self):
#   def numMatrices(self):
#   def size(self):
#   def parameterSize(self):
#   def createPartner(self):
#   def serialize(self,direc):
#   def serializeDataTo(self,fileLike,filter=None):
#   def importSerializedDataFrom(self,fileLike):
#   def deserializeDataFrom(fileLike):
#   def _saveMatDictWithScipy(fileLike,d):
#   def _restoreMatDictWithScipy(fileLike):
#   def deserialize(direc):
#   def uncache(dbFile,factFile,initSchema=None):
#   def addLines(self,lines):
#   def loadFile(filenames,initSchema=None):
#   def startBuffers(self):
#   def bufferFile(self,filename):
#   def flushBuffers(self):
#   def _flushBuffer(self,functor,arity):
#   def _bufferTriplet(self,functor,arity,a1,a2,w,filename,k):
#   def _bufferLine(self,line,filename,k):
#     def _atof(s):
# 
# Path: tensorlog/util.py
# def memusage():
# def linesIn(fileLike):
# 
# Path: tensorlog/version.py
# VERSION = '1.3.6'


import getopt
import time
import logging
from tensorlog import dataset
from tensorlog import matrixdb
from tensorlog import util
from tensorlog import version
    from tensorlog import program
    optdict['--db'] = db
    status('loading prog')
    optdict['--prog'] = parseProgSpec(optdict['--prog'],db,proppr=('--proppr' in optdict))
    status('loading prog')
    for key in ('--trainData','--testData'):
        if key in optdict:
          status('loading %s' % key[2:])
          optdict[key] = parseDatasetSpec(optdict[key],db)

    # let these be also indexed by 'train', 'prog', etc, not just '--train','--prog'
    for key,val in list(optdict.items()):
        optdict[key[2:]] = val

    status('command line parsed')
    return optdict,args

def isUncachefromSrc(s): return s.find("|")>=0
def getCacheSrcPair(s): return s.split("|")
def makeCacheSrcPair(s1,s2): return "%s|%s" % (s1,s2)

def parseDatasetSpec(spec,db):
    """Parse a specification for a dataset, see usage() for parseCommandLine"""
    if isUncachefromSrc(spec):
        cache,src = getCacheSrcPair(spec)
        assert src.endswith(".examples") or src.endswith(".exam"), 'illegal --train or --test file'
        return dataset.Dataset.uncacheExamples(cache,db,src,proppr=src.endswith(".examples"))
    elif spec.endswith(".dset"):
        return dataset.Dataset.deserialize(spec)
    else:
        assert spec.endswith(".examples") or spec.endswith(".exam"), 'illegal --train or --test file'

# Path: tensorlog/dataset.py
# class Dataset(object):
#     def __init__(self,xDict,yDict):
#     def isSinglePredicate(self):
#     def extractMode(self,mode):
#     def modesToLearn(self):
#     def hasMode(self,mode):
#     def getX(self,mode):
#     def getY(self,mode):
#     def size(self):
#     def shuffle(self):
#     def minibatchIterator(self,batchSize=100,shuffleFirst=True):
#     def pprint(self):
#     def serialize(self,dir):
#     def deserialize(dir):
#     def uncacheExamples(dsetFile,db,exampleFile,proppr=True):
#     def uncacheMatrix(dsetFile,db,functorToLearn,functorInDB):
#     def loadMatrix(db,functorToLearn,functorInDB):
#     def _parseLine(line,proppr=True):
#     def loadProPPRExamples(db,fileName):
#     def loadExamples(db,fileName,proppr=False):
#         def getId(typeName,symbol):
#     def saveProPPRExamples(self,fileName,db,append=False,mode=None):
# 
# Path: tensorlog/matrixdb.py
# NULL_ENTITY_NAME = dbschema.NULL_ENTITY_NAME
# THING = dbschema.THING
# OOV_ENTITY_NAME = dbschema.OOV_ENTITY_NAME
# TRAINABLE_DECLARATION_FUNCTOR = 'trainable'
# class MatrixDB(object):
#   def __init__(self,initSchema=None):
#   def checkTyping(self):
#   def isTypeless(self):
#   def _fillDefault(self,typeName):
#   def dim(self,typeName=None):
#   def onehot(self,s,typeName=None,outOfVocabularySymbolsAllowed=False):
#   def zeros(self,numRows=1,typeName=None):
#   def ones(self,typeName=None):
#   def nullMatrix(self,numRows=1,typeName=None,numCols=0):
#   def transposeNeeded(mode,transpose=False):
#   def matrix(self,mode,transpose=False):
#   def vector(self,mode):
#   def matrixPreimage(self,mode):
#   def matrixPreimageMat(self,mode):
#   def matrixPreimageOnesType(self,mode):
#   def matrixPreimageOnes(self,mode):
#   def isParameter(self,mode):
#   def markAsParam(self,functor,arity):
#   def markAsParameter(self,functor,arity):
#   def clearParameterMarkings(self):
#   def getParameter(self,functor,arity):
#   def parameterIsInitialized(self,functor,arity):
#   def setParameter(self,functor,arity,replacement):
#   def asSymbol(self,symbolId,typeName=None):
#   def asSymbolId(self,symbol,typeName=None):
#   def rowAsSymbolDict(self,row,typeName=None):
#   def arrayAsSymbolDict(self,arr,typeName=None):
#   def matrixAsSymbolDict(self,m,typeName=None):
#   def matrixAsPredicateFacts(self,functor,arity,m):
#   def inDB(self,functor,arity):
#   def summary(self,functor,arity):
#   def listing(self):
#   def numMatrices(self):
#   def size(self):
#   def parameterSize(self):
#   def createPartner(self):
#   def serialize(self,direc):
#   def serializeDataTo(self,fileLike,filter=None):
#   def importSerializedDataFrom(self,fileLike):
#   def deserializeDataFrom(fileLike):
#   def _saveMatDictWithScipy(fileLike,d):
#   def _restoreMatDictWithScipy(fileLike):
#   def deserialize(direc):
#   def uncache(dbFile,factFile,initSchema=None):
#   def addLines(self,lines):
#   def loadFile(filenames,initSchema=None):
#   def startBuffers(self):
#   def bufferFile(self,filename):
#   def flushBuffers(self):
#   def _flushBuffer(self,functor,arity):
#   def _bufferTriplet(self,functor,arity,a1,a2,w,filename,k):
#   def _bufferLine(self,line,filename,k):
#     def _atof(s):
# 
# Path: tensorlog/util.py
# def memusage():
# def linesIn(fileLike):
# 
# Path: tensorlog/version.py
# VERSION = '1.3.6'


# Path: tensorlog/comline.py
import getopt
import time
import logging
from tensorlog import dataset
from tensorlog import matrixdb
from tensorlog import util
from tensorlog import version
    from tensorlog import program

    optdict['--db'] = db
    status('loading prog')
    optdict['--prog'] = parseProgSpec(optdict['--prog'],db,proppr=('--proppr' in optdict))
    status('loading prog')
    for key in ('--trainData','--testData'):
        if key in optdict:
          status('loading %s' % key[2:])
          optdict[key] = parseDatasetSpec(optdict[key],db)

    # let these be also indexed by 'train', 'prog', etc, not just '--train','--prog'
    for key,val in list(optdict.items()):
        optdict[key[2:]] = val

    status('command line parsed')
    return optdict,args

def isUncachefromSrc(s): return s.find("|")>=0
def getCacheSrcPair(s): return s.split("|")
def makeCacheSrcPair(s1,s2): return "%s|%s" % (s1,s2)

def parseDatasetSpec(spec,db):
    """Parse a specification for a dataset, see usage() for parseCommandLine"""
    if isUncachefromSrc(spec):
        cache,src = getCacheSrcPair(spec)
        assert src.endswith(".examples") or src.endswith(".exam"), 'illegal --train or --test file'
        return dataset.Dataset.uncacheExamples(cache,db,src,proppr=src.endswith(".examples"))
    elif spec.endswith(".dset"):
        return dataset.Dataset.deserialize(spec)
    else:
        assert spec.endswith(".examples") or spec.endswith(".exam"), 'illegal --train or --test file'

        return dataset.Dataset.loadExamples(db,spec,proppr=spec.endswith(".examples"))