Praat scripting: How to get rid of "_" in accent tier and it's corresponding syllables in Info Window? - praat

I have a point tier that shows accents. I also have a syllable tier. I need to extract the labels of the syllable tier with the corresponding accents. The only thing that I don't need is the extracting of the label "_" and "%" in the accent tier.
My code so far:
writeInfo: ""
selectObject: "TextGrid example"
number = Get number of points: 2 #for the accent tier
for n from 1 to number
accent_time = Get time of point: 2, n
syllable = Get interval at time: 1, accent_time #for the syllable tier
syllable$ = Get label of interval: 1, syllable
accent$ = Get label of point: 2, n
#if accent$ = "_" and "%"
#don't append syllable
#endif
appendInfoLine: syllable$, " ",accent$
endfor
Result:
"Ra:n H*L
"tOm H*
gRam L*H
"tROts -
"tROts H*L
"u: H*L
"tsjo:n -
"fEst H*L
What I'm aiming to get:
"Ra:n H*L
"tOm H*
gRam L*H
"tROts H*L
"u: H*L
"fEst H*L

writeInfo: ""
selectObject: "TextGrid example"
number = Get number of points: 2 #for the accent tier
for n from 1 to number
accent_time = Get time of point: 2, n
syllable = Get interval at time: 1, accent_time #for the syllable tier
syllable$ = Get label of interval: 1, syllable
accent$ = Get label of point: 2, n
if accent$ <> "_" and accent$ <> "%"
appendInfoLine: syllable$, " ",accent$
endif
endfor

Related

Calculating average of numbers in a text file using VBScript

I am trying to calculate the average between all the numbers in a text file (every number is on a different line), no matter how many numbers there are. (Using VBScript)
Here is an example of the text file that I am trying to find the average between its numbers:
1
9
4
4
2
Also, sorry if I didn't word this well, it's my first question.
Can you try this script (I suppose that numbers are integer):
filename = "myfile.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
i = 0 'Elements number
sum = 0 'Sum of values
Do Until f.AtEndOfStream
sum = sum + CInt(trim(f.ReadLine))
i = i + 1
Loop
avg = sum / i 'Calculate the average
f.Close
Thank you

Praat scripting: How to extract max of pitch for every syllable?

I want to extract the maximum pitch for every syllable.
I have a piece of code, but it throws an error:
writeInfoLine: ""
selectObject: "TextGrid example", "Pitch example"
# syllable tier is 1
number = Get number of intervals: 1
for i from 1 to number
name$ = Get label of interval: 1, i
start_time = Get start time of interval: 1, i
end_time = Get end time of interval: 1, i
max_pitch = Get maximum: start_time, end_time, "Hertz", "Parabolic"
appendInfoLine: name$, " ", max_pitch
endfor
Here's a script with instructions on how to run it. It jumps back and forth between your TextGrid and Pitch object.
# open your wav file and textgrid into objects window
# select wav file
# run script
clearinfo
objName$ = selected$ ("Sound")
To Pitch: 0, 75, 600
select TextGrid 'objName$'
intervals = Get number of intervals: 1
printline 'intervals' intervals in textgrid
for i from 1 to intervals
# need var$ because it's a string
lab$ = Get label of interval: 1, i
start = Get start time of interval: 1, i
end = Get end time of interval: 1, i
# now look at the Intensity object
select Pitch 'objName$'
max = Get maximum: start, end, "Hertz", "Parabolic"
printline 'start' 'end' 'lab$' 'max'
# reset for next iteration
select TextGrid 'objName$'
endfor

Microsoft Access - Label Printing - each 10 labels to print vertically

Good day, I am having an issue, I need to print 3000 lables every 7 days and they are cut in to individual lables, at the moment they are printing in sequence 1,2,3,4,5,6...etc, so person wastes time to pick them up and put them in correct slots
Now what I need is that record Number 2 is printed on 2nd page, 3rd record on page 3 and like this 10 pages, my 11 record under is on 1st page just below record number 1, record 12 is on page 2 under record number 2.....
So idea is that person can grab a stack of 10 record instead of taking them one by one, but I am not sure how can I do it=\ any Ideas?
' Macro to assign numbers to data source so that it can be sorted to cause labels to print down columns
Dim Message, Title, Default, labelrows, labelcolumns,
i As Integer, j As Integer,
k As Integer
Message = "Enter the number of labels in a row" ' Set prompt.
Title = "Labels per Row" ' Set title.
Default = "3" ' Set default.
' Display message, title, and default value.
labelcolumns = InputBox(Message, Title, Default)
Message = "Enter the number of labels in a column" ' Set prompt.
Title = "Labels per column" ' Set title.
Default = "5" ' Set default.
labelrows = InputBox(Message, Title, Default)
ActiveDocument.Tables(1).Columns.Add
BeforeColumn:=ActiveDocument.Tables(1).Columns(1)
ActiveDocument.Tables(1).Rows(1).Range.Cut
k = 1
For i = 1 To ActiveDocument.Tables(1).Rows.Count - labelcolumns
For j = 1 To labelrows
ActiveDocument.Tables(1).Cell(i, 1).Range.InsertBefore k + (j - 1) *
labelcolumns
i = i + 1
Next j
k = k + 1
i = i - 1
If k Mod labelcolumns = 1 Then k = k - labelcolumns + labelcolumns *
labelrows
Next i
ActiveDocument.Tables(1).Sort FieldNumber:="Column 1"
ActiveDocument.Tables(1).Rows(1).Select
Selection.Paste
ActiveDocument.Tables(1).Columns(1).Delete
this one I had was for word, unfortunately it didn't work exactly the way I need

Convert alphanumeric string to given values for each, then add them for a total number

I'm having a difficult time wording exactly what I'm doing, but basically I have variable length alphanumeric data being fed to a program, and I want to find out the total "pixel width" of the string, based on a fixed list of A = 3 pxl, B = 3 pxl, I = 1 pxl, etc...
I would list all of the pixel values of each letter and number, and then would like the script to take the input: ex. "THIS IS THE STRING", and convert it to the numbers I've assigned add them up and total them giving me the total sum as an output (I would also assign a number for a space " " and punctuation).
So: "THIS IS A STRING" would be "3+3+1+3+2+1+3+2+3+3+3+2+3+3+3+1+3+3 = 45"
You need a table/array of pixel widthes indexed by ASCII codes. Then you can loop over the string's characters and sum the widthes. Like:
>> Dim a(255)
>> a(65) = 3
>> a(66) = 3
>> a(Asc("I")) = 1
>> s = "AIB"
>> n = 0
>> For p = 1 To Len(s)
>> n = n + a(Asc(Mid(s, p, 1)))
>> Next
>> WScript.Echo n
>>
7

Algorithm to find the most common substrings in a string

Is there any algorithm that can be used to find the most common phrases (or substrings) in a string? For example, the following string would have "hello world" as its most common two-word phrase:
"hello world this is hello world. hello world repeats three times in this string!"
In the string above, the most common string (after the empty string character, which repeats an infinite number of times) would be the space character .
Is there any way to generate a list of common substrings in this string, from most common to least common?
This is as task similar to Nussinov algorithm and actually even simpler as we do not allow any gaps, insertions or mismatches in the alignment.
For the string A having the length N, define a F[-1 .. N, -1 .. N] table and fill in using the following rules:
for i = 0 to N
for j = 0 to N
if i != j
{
if A[i] == A[j]
F[i,j] = F [i-1,j-1] + 1;
else
F[i,j] = 0;
}
For instance, for B A O B A B:
This runs in O(n^2) time. The largest values in the table now point to the end positions of the longest self-matching subquences (i - the end of one occurence, j - another). In the beginning, the array is assumed to be zero-initialized. I have added condition to exclude the diagonal that is the longest but probably not interesting self-match.
Thinking more, this table is symmetric over diagonal so it is enough to compute only half of it. Also, the array is zero initialized so assigning zero is redundant. That remains
for i = 0 to N
for j = i + 1 to N
if A[i] == A[j]
F[i,j] = F [i-1,j-1] + 1;
Shorter but potentially more difficult to understand. The computed table contains all matches, short and long. You can add further filtering as you need.
On the next step, you need to recover strings, following from the non zero cells up and left by diagonal. During this step is also trivial to use some hashmap to count the number of self-similarity matches for the same string. With normal string and normal minimal length only small number of table cells will be processed through this map.
I think that using hashmap directly actually requires O(n^3) as the key strings at the end of access must be compared somehow for equality. This comparison is probably O(n).
Python. This is somewhat quick and dirty, with the data structures doing most of the lifting.
from collections import Counter
accumulator = Counter()
text = 'hello world this is hello world.'
for length in range(1,len(text)+1):
for start in range(len(text) - length):
accumulator[text[start:start+length]] += 1
The Counter structure is a hash-backed dictionary designed for counting how many times you've seen something. Adding to a nonexistent key will create it, while retrieving a nonexistent key will give you zero instead of an error. So all you have to do is iterate over all the substrings.
just pseudo code, and maybe this isn't the most beautiful solution, but I would solve like this:
function separateWords(String incomingString) returns StringArray{
//Code
}
function findMax(Map map) returns String{
//Code
}
function mainAlgorithm(String incomingString) returns String{
StringArray sArr = separateWords(incomingString);
Map<String, Integer> map; //init with no content
for(word: sArr){
Integer count = map.get(word);
if(count == null){
map.put(word,1);
} else {
//remove if neccessary
map.put(word,count++);
}
}
return findMax(map);
}
Where map can contain a key, value pairs like in Java HashMap.
Since for every substring of a String of length >= 2 the text contains at least one substring of length 2 at least as many times, we only need to investigate substrings of length 2.
val s = "hello world this is hello world. hello world repeats three times in this string!"
val li = s.sliding (2, 1).toList
// li: List[String] = List(he, el, ll, lo, "o ", " w", wo, or, rl, ld, "d ", " t", th, hi, is, "s ", " i", is, "s ", " h", he, el, ll, lo, "o ", " w", wo, or, rl, ld, d., ". ", " h", he, el, ll, lo, "o ", " w", wo, or, rl, ld, "d ", " r", re, ep, pe, ea, at, ts, "s ", " t", th, hr, re, ee, "e ", " t", ti, im, me, es, "s ", " i", in, "n ", " t", th, hi, is, "s ", " s", st, tr, ri, in, ng, g!)
val uniques = li.toSet
uniques.toList.map (u => li.count (_ == u))
// res18: List[Int] = List(1, 2, 1, 1, 3, 1, 5, 1, 1, 3, 1, 1, 3, 2, 1, 3, 1, 3, 2, 3, 1, 1, 1, 1, 1, 3, 1, 3, 3, 1, 3, 1, 1, 1, 3, 3, 2, 4, 1, 2, 2, 1)
uniques.toList(6)
res19: String = "s "
Perl, O(n²) solution
my $str = "hello world this is hello world. hello world repeats three times in this string!";
my #words = split(/[^a-z]+/i, $str);
my ($display,$ix,$i,%ocur) = 10;
# calculate
for ($ix=0 ; $ix<=$#words ; $ix++) {
for ($i=$ix ; $i<=$#words ; $i++) {
$ocur{ join(':', #words[$ix .. $i]) }++;
}
}
# display
foreach (sort { my $c = $ocur{$b} <=> $ocur{$a} ; return $c ? $c : split(/:/,$b)-split(/:/,$a); } keys %ocur) {
print "$_: $ocur{$_}\n";
last if !--$display;
}
displays the 10 best scores of the most common sub strings (in case of tie, show the longest chain of words first). Change $display to 1 to have only the result.There are n(n+1)/2 iterations.

Resources