def _load_dir(self, dir: str) -> Tuple[np.ndarray, np.ndarray]:
        pos_files = listfiles(os.path.join(DATA_PATH, dir, 'pos'))
        pos_x = np.zeros(shape=(len(pos_files), self.input_length))
        for i, file in enumerate(pos_files):
            pos_x[i] = self._file_to_word_ids(
                os.path.join(DATA_PATH, dir, 'pos', file))

        neg_files = listfiles(os.path.join(DATA_PATH, dir, 'neg'))
        neg_x = np.zeros(shape=(len(neg_files), self.input_length))
        for i, file in enumerate(neg_files):
            neg_x[i] = self._file_to_word_ids(
                os.path.join(DATA_PATH, dir, 'neg', file))

        x = np.concatenate([pos_x, neg_x])
        y = np.array([1] * len(pos_files) + [0] * len(neg_files))
        y = y.reshape((len(y), 1))
        return x, y
Beispiel #2
0
    #expected, actual = [], []
    expected, actual = dict(), dict()

    self.runTp(inputPath, outputPath)

    with open(expectedPath, 'r') as fexpected:
      fexpected.readline() # ignore time
      fexpected.readline() # ignore size
      expected = [int(x.strip()) for x in fexpected.readline().split() if len(x.strip()) > 0]

    with open(outputPath, 'r') as factual:
      factual.readline() # ignore time
      factual.readline() # ignore size
      actual = [int(x.strip()) for x in factual.readline().split() if len(x.strip()) > 0]

    self.assertEqual(len(expected), len(actual), "Se esperaban {0} valores en la solucion pero se encontraron {1}".format(len(expected), len(actual)))
    for index, (a, e) in enumerate(zip(actual, expected)):
      self.assertAlmostEqual(a, e, delta=0.0001, msg="Se esperaba {0} en la linea {1} pero se encontro {2}".format(e,index+1,a))


def addTest(cls, inputPath, expectedPath, outputPath):
  """Registra un test nuevo dinamicamente"""
  def dynamicTest(self): self.assertRun(inputPath, expectedPath, outputPath)
  tname = inputPath.replace("\\", "_").replace("/", "_").replace(".in", "")
  setattr(cls, tname, dynamicTest)


# Para cada archivo .in en la carpeta tests o cualquier subcarpeta, registra un nuevo test dinamicamente, verificando que la salida tenga el mismo contenido que el archivo con igual nombre pero extension .expected
for fname in listfiles('tests', '*.in'):
  addTest(Tp1TestCase, fname, fname.replace(".in", ".expected"), fname.replace(".in", ".out"))
Beispiel #3
0
    """Invoca al tp con input y output como parametros"""
    check_call([settings.executable, input, output] + settings.extraParams, stdin=None, stdout=PIPE, stderr=PIPE)

  def assertRun(self, inputPath, expectedPath, outputPath):
    """Ejecuta tp.exe, pasando como parametros inputPath y outputPath, y verifica que la salida generada coincida con el contenido del archivo en expectedPath"""
    expected, actual = [], []

    self.runTp(inputPath, outputPath)

    with open(expectedPath, 'r') as fexpected:
      expected = [float(x.strip()) for x in fexpected.readlines() if len(x.strip()) > 0]

    with open(outputPath, 'r') as factual:
      actual = [float(x.strip()) for x in factual.readlines() if len(x.strip()) > 0]

    #self.assertEqual(len(expected), len(actual), "Se esperaban {0} valores en la solucion pero se encontraron {1}".format(len(expected), len(actual)))
    for index, (a, e) in enumerate(zip(actual, expected)):
      self.assertAlmostEqual(a, e, delta=0.001, msg="Se esperaba {0} en la linea {1} pero se encontro {2}".format(e,index+1,a))


def addTest(cls, inputPath, expectedPath, outputPath):
  """Registra un test nuevo dinamicamente"""
  def dynamicTest(self): self.assertRun(inputPath, expectedPath, outputPath)
  tname = inputPath.replace("\\", "_").replace("/", "_").replace(".in", "")
  setattr(cls, tname, dynamicTest)


# Para cada archivo .in en la carpeta tests o cualquier subcarpeta, registra un nuevo test dinamicamente, verificando que la salida tenga el mismo contenido que el archivo con igual nombre pero extension .expected
for fname in listfiles('tests', '*.in'):
  addTest(Tp1TestCase, fname, fname.replace(".in", ".expected"), fname.replace(".in", ".out"))
Beispiel #4
0
import os
from utils import listfiles

# Sources listadas manualmente
# sources = ['main', 'utils', 'utils2/utils2']

# Sources listadas automaticamente
sources = [f[:f.rfind('.')] for f in listfiles('.', '*.cpp')]

# Compilador
compiler = 'g++'

# Programa compilado
executable = './tp' if os.name == 'posix' else 'tp.exe'

# Parametros extra
extraParams = ['1']

Beispiel #5
0
                if len(x.strip()) > 0
            ]

        self.assertEqual(
            len(expected), len(actual),
            "Se esperaban {0} valores en la solucion pero se encontraron {1}".
            format(len(expected), len(actual)))
        for index, (a, e) in enumerate(zip(actual, expected)):
            self.assertAlmostEqual(
                a,
                e,
                delta=1,
                msg="Se esperaba {0} en la linea {1} pero se encontro {2}".
                format(e, index + 1, a))


def addTest(cls, inputPath, expectedPath, outputPath):
    """Registra un test nuevo dinamicamente"""
    def dynamicTest(self):
        self.assertRun(inputPath, expectedPath, outputPath)

    tname = inputPath.replace("\\", "_").replace("/", "_").replace(".in", "")
    setattr(cls, tname, dynamicTest)


# Para cada archivo .in en la carpeta tests o cualquier subcarpeta, registra un nuevo test dinamicamente, verificando que la salida tenga el mismo contenido que el archivo con igual nombre pero extension .expected
#for fname in listfiles('tests', '*.in'):
for fname in listfiles('tests/catedra', '*.in'):
    addTest(Tp1TestCase, fname, fname.replace(".in", ".expected"),
            fname.replace(".in", ".out"))
import os
from utils import listfiles

# Sources listadas manualmente
# sources = ['main', 'utils', 'utils2/utils2']

# Sources listadas automaticamente
sources = [f.rstrip('.cpp') for f in listfiles('.', '*.cpp')]

# Compilador
compiler = 'g++'

# Programa compilado
executable = './tp2' if os.name == 'posix' else 'tp2.exe'

# Parametros extra
extraParams = []

Beispiel #7
0
import os
from utils import listfiles

# Sources listadas manualmente
# sources = ['main', 'utils', 'utils2/utils2']

# Sources listadas automaticamente
sources = [f.rstrip('.cpp') for f in listfiles('.', '*.cpp')]

# Compilador
compiler = 'g++'

# Programa compilado
executable = '../bin/tp1' if os.name == 'posix' else 'tp.exe'

# Parametros extra
# extraParams = ['1'] # calculo que esto es el parametro de que metodo de resolucion usar
# esto se cambio por un argumento de linea de comando

Beispiel #8
0
import os
from utils import listfiles

# Sources listadas manualmente
# sources = ['main', 'utils', 'utils2/utils2']

# Sources listadas automaticamente
# sources = [f.rstrip('.cpp') for f in listfiles('.', '*.cpp')]
sources = [f[: f.rfind(".")] for f in listfiles(".", "*.cpp")]

# Compilador
compiler = "g++"

# Programa compilado
executable = "./tp" if os.name == "posix" else "tp.exe"

# Parametros extra
extraParams = ["-std=c++0x", "-g"]
"""Downloads Youtube videos.

"""

import os
import sys
from pytube import YouTube
from pprint import pprint
import settings
import utils

# gets list of video IDS that have already been downloaded.
# note: each video ID has a '.mp4' suffix.
output_dir = os.path.join(settings.DATA_DIR, 'videos', 'downloads')
downloaded_videos = [
    fname for fname in utils.listfiles(output_dir) if not fname.startswith('.')
]

# loads all video IDs that are predicted to be speeches.
# video_ids = utils.get_speech_video_ids()

# TEMPORARY: loads all video IDs from the channel "Raila Odinga vs Uhuru Kenyatta 2017"
videos = utils.get_videos()
video_ids = videos[videos.channel_title ==
                   "Raila Odinga vs Uhuru Kenyatta 2017"].video_id

# downloads videos by video ID.
msg = 'You are about to attempt to download {0} videos. Do you wish to continue ([y]es/[n]o)?'.format(
    video_ids.shape[0])
s = input(msg)
if s in ['yes', 'y']: