Beispiel #1
0
    def print_targets(self, targets, output_filename=None, trs=None):
        """ Print the set of selected targets.

        :param targets:
        :param output_filename: (str)
        :param trs: (Transcription)

        """
        if output_filename is not None:
            if output_filename is "STDOUT":
                output = sys.stdout
                self.__print_tgts(targets, output)
            elif output_filename.lower().endswith('momel') is True:
                output = open(output_filename, "w")
                self.__print_tgts(targets, output)
                output.close()

        if trs is not None:
            # Attention: time in targets is in milliseconds!
            tier = trs.NewTier(name="Momel")
            for i in range(len(targets)):
                _time = targets[i].get_x() * (0.001 * self.PAS_TRAME)
                _label = str("%d" % (targets[i].get_y()))
                try:
                    tier.Append(Annotation(TimePoint(_time), Label(_label)))
                except Exception:
                    if self.logfile is not None:
                        self.logfile.print_message("Ignore target: time=" +
                                                   str(_time) + " and value=" +
                                                   _label,
                                                   indent=2,
                                                   status=3)

            if output_filename is not None and output_filename.lower(
            ).endswith('.pitchtier'):
                trsp = Transcription()
                trsp.Add(tier)
                try:
                    sppas.src.annotationdata.aio.write(output_filename, trsp)
                except Exception:
                    if self.logfile is not None:
                        self.logfile.print_message(
                            "Can't write PitchTier output file.", status=-1)
            return tier
Beispiel #2
0
if tieridx < 0 or tieridx > trs.GetSize():
    print('Error: Bad tier number.\n')
    sys.exit(1)

tier = trs[tieridx]
if not mode:
    mode.append(0)

d = {0: 'exact', 1: 'contains', 2: 'startswith', 3: 'endswith', 4: 'regexp'}
prefix = "" if "CASE_SENSITIVE" in options else "i"
bools = [Sel(**{prefix + d[key]: p}) for key in mode for p in patterns]
pred = functools.reduce(operator.or_, bools)
pred = ~pred if "REVERSE" in options else pred

filtered_annotations = filter(pred, tier)
if not filtered_annotations:
    print("NO RESULT")
    sys.exit(0)

filteredtier = Tier(tier.Name)
for a in filtered_annotations:
    filteredtier.Add(a)

if fileoutput is None:
    for a in filteredtier:
        print(a)
else:
    trs = Transcription()
    trs.Add(filteredtier)
    sppas.src.annotationdata.aio.write(fileoutput, trs)
Beispiel #3
0
    label = Label(max_dist, data_type="float")

    a = Annotation(TimeInterval(begin, end), label)
    filtered_tier.Append(a)

#     for i in range(idxbegin,idxend+1):
#         print windows[i],distances[i]
#         for j in range (w):
#             print tier[i+j].GetLocation().GetDuration().GetValue(),tier[i+j].GetLabel().GetValue(), "/",
#     print " -> maxdist=",maxdist
#     print a
#     print

# ----------------------------------------------------------------------------
# Save result

if file_output is None:
    for a in filtered_tier:
        print(a)
else:
    trs = Transcription()
    trs.Add(filtered_tier)

    #     t = Tier('PhonAlign30')
    #     for v,a in zip(values,tier):
    #         if v == 1:
    #             t.Append(a)
    #     trs.Add(t)

    sppas.src.annotationdata.aio.write(file_output, trs)
Beispiel #4
0
# ----------------------------------------------------------------------------
# Read

trs_input = sppas.src.annotationdata.aio.read(args.i)
trs_out = Transcription()

# ----------------------------------------------------------------------------
# Transform the PhonAlign tier to a Phonetization tier

try:
    align_tier = sppasSearchTier.aligned_phones(trs_input)
    logging.info("PhonAlign tier found.")
    phon_tier = unalign(align_tier)
    phon_tier.SetName("Phones")
    trs_out.Add(phon_tier)
except IOError:
    logging.info("PhonAlign tier not found.")

# ----------------------------------------------------------------------------
# Transform the TokensAlign tier to a Tokenization tier

if args.tok:
    try:
        align_tier = sppasSearchTier.aligned_tokens(trs_input)
        logging.info("TokensAlign tier found.")
        token_tier = unalign(align_tier)
        token_tier.SetName("Tokens")
        trs_out.Add(token_tier)
    except IOError:
        logging.info("TokensAlign tier not found.")