def test_value_change():
    start_val = 5
    new_val = 20

    example = Example(start_val)
    example.update_value(new_val)
    assert example.get_value() == new_val and example.get_previous_value() == start_val
Example #2
0
def read_data(max=None):
    result = []
    letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']

    max_images_per_letter = float("+inf")
    if max != None:
        max_images_per_letter = max / len(letters)

    for i, letter in enumerate(letters):

        num_images_read_for_letter = 0
        for image_path in glob.glob("../data/" + letter + "/*.png"):

            img = misc.imread(name=image_path).flatten().tolist()
            vector_div_inplace(img, 128)
            result.append(Example(img, i, 10))

            num_images_read_for_letter += 1
            if num_images_read_for_letter >= max_images_per_letter:
                break

    random.shuffle(result)

    break_index = int(len(result) * test_ratio)

    test_data = result[0:break_index]
    train_data = result[break_index + 1:]

    return train_data, test_data
Example #3
0
def create_example():
    from {{cookiecutter.app_name}}.models import Example
    click.echo("create example entry")
    entry = Example(
        name='test-entry'
    )
    db.session.add(entry)
    db.session.commit()
    click.echo("created test example entry")
Example #4
0
def admin_user(db):
    entry = Example(
        name='example-test',
    )

    db.session.add(entry)
    db.session.commit()

    return entry
    def test_create_duplicate(self):
        """
        Examples enforce uniqueness on type/external id.

        """
        example1 = Example(
            name=self.name,
        )
        example2 = Example(
            name=self.name,
        )

        with transaction():
            self.example_store.create(example1)

        assert_that(
            calling(self.example_store.create).with_args(example2),
            raises(DuplicateModelError),
        )
    def setup(self):
        self.graph = create_app(testing=True)
        self.client = self.graph.flask.test_client()
        recreate_all(self.graph)

        self.name1 = "name1"

        self.example1 = Example(
            id=new_object_id(),
            name=self.name1,
        )
Example #7
0
    def readDataFile(self, dataFile, schemeAttributes):
       
        #The number associated with each example
        exampleNum = 1

        try:

            #Read the sample file in its entirety
            with open(dataFile, "r") as sampleReader:
                headerLine = sampleReader.readline()

                #If the header line's variables are out of order or missing, exit the program
                if (self.verifyHeaderLine(headerLine) == False):
                    print("One or more of the header variables in the data file are out of order or missing.")
                    sampleReader.close()
                    exit(1)

                #Read the first example line in the DataFile
                fileLine = sampleReader.readline()

                #Read every Example from the DataFile
                while (fileLine != None and fileLine != ""):
                    fileLine = fileLine.strip()
                    fileLine = fileLine.replace("\t\t", " ")
                    fileLine = fileLine.replace("\t", " ")
                    fileLine = fileLine.replace(" +", " ")

                    #Create a new Example using the file line
                    dataExample = Example(exampleNum, fileLine, schemeAttributes)

                    #If the example read was invalid, stop reading the file and exit the program
                    if (dataExample.getAttributeValues() == None):
                        sampleReader.close()
                        exit(1)

                    #Else, add the example to the example set
                    else:
                        self.exampleSet.append(dataExample)

                    #Increment the count of the number of examples
                    exampleNum += 1

                    #Read the next example in the file
                    fileLine = sampleReader.readline()

        #If the file couldn't be found, inform the user
        except FileNotFoundError:
            print("The data file " + dataFile + " could not be found")

        #If an error occurred while reading the file, inform the user
        except IOError:
            print("An error occurred while reading the data file " + dataFile)
Example #8
0
def readData(fileName):
    dataFileHandle = open(fileName, 'r')
    exampleLines = dataFileHandle.readlines()
    examples = []
    for example in exampleLines:
        example = example.strip()
        example = preprocess(example)
        toks = example.split(' ', 1)
        classTag = toks[0]
        text = toks[1]
        ex = Example(classTag, text)
        examples.append(ex)
    return examples
    def test_create(self):
        """
        Examples can be persisted.

        """
        new_example = Example(
            name=self.name,
        )

        with transaction():
            self.example_store.create(new_example)

        retrieved_example = self.example_store.retrieve(new_example.id)
        assert_that(retrieved_example, is_(equal_to(new_example)))
    async def create_mock(cls, user_input: Dict[str, Any] = None, expected_db_data: Dict[str, Any] = None) -> Example:
        """
        Creates a new mocked Example and returns it using the user's input (what the user typed in when
        creating the instance, and the expected DB data (what the database is expected to return if the
        instance/record creation was successful)
        """
        _user_input = {**cls.user_input_template, **(user_input or {})}
        _expected_db_data = {**cls.expected_db_data_template, **(expected_db_data or {})}

        example_instance = Example(**_user_input)

        for attr_name, attr_value in _expected_db_data.items():
            setattr(example_instance, attr_name, attr_value)

        return example_instance
Example #11
0
def learnConstraints(filename, sheet, data_ranges):
    constraints = []
    variables = []
    for data_range in data_ranges:
        ex = Example.Example(filename, sheet, data_range)
        dataTensor, variables = ex.get_dimensions_and_data()
        dataTensor = dataTensor.transpose((1, 2, 0))
        variables = [variables[1], variables[2], variables[0]]

        lenVar = []
        for i in range(len(variables)):
            lenVar.append(len(variables[i]))
        orderingNotImp = [0]
        constraints.append(
            getConstraintsForAll(dataTensor, variables, orderingNotImp))
    #    print(constraints)
    return constraints, [variables[2], variables[0], variables[1]]
    def test_retrieve_by_name(self):
        """
        Examples can be retrieved by name.

        """
        new_example = Example(
            name=self.name,
        )

        with transaction():
            self.example_store.create(new_example)

        retrieved_example = self.example_store.retrieve_by_name(
            self.name
        )

        assert_that(retrieved_example, is_(equal_to(new_example)))
def main():
    try:
        args = Args()
        dbg = args.debug

        # Do your work here - preferably in a class or function,
        # passing in your args. E.g.
        exe = Example(args.first)
        exe.update_value(args.second)
        print(
            "First : {}\nSecond: {}".format(exe.get_value(), exe.get_previous_value())
        )

    except Exception as e:
        log.error("=============================================")
        if dbg:
            log.error("\n\n" + traceback.format_exc())
            log.error("=============================================")
        log.error("\n\n" + str(e) + "\n")
        log.error("=============================================")
        sys.exit(1)
Example #14
0
 async def create_new_examples():
     async with transactional_session() as session:
         for i in range(1, 5):
             session.add(Example(name=f"Example #{i}"))
             session.commit()
Example #15
0
def test_integration():
    task = Example()
    success = luigi.build([task], scheduler_host='localhost')
    assert success
Example #16
0
def test_example():
    e = Example()
    assert e.get_value() == 10
Example #17
0
from Config import *
from FeatureExtractorModule import *
from Example import *

print "Loading the model..."
pickledModelFileHandle = open(pickledModelFileName, 'rb')
svcModelLoaded = pickle.load(pickledModelFileHandle)
svcModel = svcModelLoaded['model']

print "Load and Set the feature extractors..."
pickledFeatureExtractorsFileHandle = open(pickledFeatureExtractorsFileName,
                                          'rb')
featureExtractors = pickle.load(pickledFeatureExtractorsFileHandle)
setFeatureExtractors(featureExtractors)

print "Read the test examples"
testingDataFileHandle = open(testingDataFileName, 'rb')
exampleLines = testingDataFileHandle.readlines()
testingExamples = []
for example in exampleLines:
    example = example.strip()
    ex = Example("", example)
    testingExamples.append(ex)

print "Extracting the features..."
testingClasses, testingFeatures = extractFeatures(testingExamples, False)

print "Inferencing..."
predictedClasses = svcModel.predict(testingFeatures)
for predictedClass in predictedClasses:
    print "The type of the question is: " + predictedClass
def test_parameterized_value_change_with_exceptions(
    start_val, next_val, expected_values
):
    example = Example(start_val)
    example.update_value(next_val)
    assert expected_values == example.values