Binomial distribution in VMS
#46
(27-08-2024, 10:57 PM)ReneZ wrote: You are not allowed to view links. Register or Login to view.You should be able to get identical results. That is not an unachievable ideal. It should be possible.

I have checked my procedure again and corrected it. Here are all the steps again (now with the complete VMS file):

ivtt -x7 ZL3a-n.txt ZLall.txt

./prep_file2.sh ZLall.txt ZLall2.txt

Code:
#!/bin/bash # Check if the correct number of arguments has been passed if [ "$#" -ne 2 ]; then     echo "Usage: $0 <inputfile> <outputfile>"     exit 1 fi # Input file and output file from the arguments inputfile="$1" outputfile="$2" # Perform character replacements and write to the output file, remove empty lines sed -e 's/@[^;]*;/w/g' \     -e '/^$/d' "$inputfile" > "$outputfile" # Print success message echo "The file has been successfully written to $outputfile."


python3 freq_chars_bigramme.py ZLall2.txt freqs.txt

Code:
import sys from collections import Counter import re # Function to calculate digram (bigram) frequency within words def calculate_digram_frequency(filepath):     # Read file content     with open(filepath, 'r', encoding='utf-8') as file:         text = file.read().lower()     # Replace non-letter characters with spaces, except within words     text = re.sub(r'[^a-z\s]', ' ', text)     # Split text into words based on spaces     words = text.split()     # List to store bigrams     bigrams = []     # Generate bigrams within each word     for word in words:         if len(word) >= 2:             bigrams.extend(word[i:i+2] for i in range(len(word) - 1))     # Count the occurrences of each bigram     counter = Counter(bigrams)     return counter, len(bigrams) # Main program if __name__ == "__main__":     if len(sys.argv) != 3:         print("Usage: python program.py <input_filepath> <output_filepath>")         sys.exit(1)     input_filepath = sys.argv[1]  # Input file as an argument     output_filepath = sys.argv[2]  # Output file as an argument     # Calculate frequencies     counter, total_bigram_count = calculate_digram_frequency(input_filepath)     # Sort bigrams by frequency and select the top 12     top_bigrams = counter.most_common(12)     # Write the top 12 bigrams to the output file     with open(output_filepath, 'w', encoding='utf-8') as output_file:         output_file.write("  No.  Bigram Frequency (in %) Frequency\n")         for i, (bigram, frequency) in enumerate(top_bigrams, 1):             bigram_upper = bigram.upper()  # Convert bigram to uppercase             frequency_percentage = (frequency / total_bigram_count) * 100 if total_bigram_count > 0 else 0.0             output_file.write(f"{i:>4} {bigram_upper:>8} {frequency_percentage:>13.4f} {frequency:>10}\n")

No.  Bigram Frequency (in %) Frequency
  1      CH        7.1043      11081
  2      HE        5.3008      8268
  3      DY        4.4623      6960
  4      AI        4.3533      6790
  5      OK        3.9615      6179
  6      IN        3.8750      6044
  7      OL        3.6121      5634
  8      EE        3.4038      5309
  9      QO        3.3961      5297
  10      ED        3.2800      5116
  11      II        3.0550      4765
  12      SH        2.9062      4533


If anyone finds any errors I would be grateful for information.
Reply


Messages In This Thread
Binomial distribution in VMS - by bi3mw - 17-08-2024, 12:33 AM
RE: Binomial distribution in VMS - by bi3mw - 17-08-2024, 12:28 PM
RE: Binomial distribution in VMS - by bi3mw - 17-08-2024, 12:47 PM
RE: Binomial distribution in VMS - by RobGea - 17-08-2024, 03:35 PM
RE: Binomial distribution in VMS - by RobGea - 17-08-2024, 04:38 PM
RE: Binomial distribution in VMS - by bi3mw - 17-08-2024, 06:38 PM
RE: Binomial distribution in VMS - by nablator - 18-08-2024, 08:18 PM
RE: Binomial distribution in VMS - by bi3mw - 18-08-2024, 01:44 PM
RE: Binomial distribution in VMS - by nablator - 18-08-2024, 05:06 PM
RE: Binomial distribution in VMS - by RobGea - 18-08-2024, 04:14 PM
RE: Binomial distribution in VMS - by bi3mw - 18-08-2024, 04:46 PM
RE: Binomial distribution in VMS - by bi3mw - 18-08-2024, 05:36 PM
RE: Binomial distribution in VMS - by nablator - 18-08-2024, 06:45 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 06:08 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 06:43 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 07:09 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 07:49 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 08:36 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 09:06 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 09:12 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 09:40 PM
RE: Binomial distribution in VMS - by bi3mw - 20-08-2024, 03:30 PM
RE: Binomial distribution in VMS - by bi3mw - 21-08-2024, 05:40 PM
RE: Binomial distribution in VMS - by Koen G - 21-08-2024, 07:06 PM
RE: Binomial distribution in VMS - by bi3mw - 21-08-2024, 07:11 PM
RE: Binomial distribution in VMS - by Koen G - 21-08-2024, 07:25 PM
RE: Binomial distribution in VMS - by bi3mw - 21-08-2024, 07:39 PM
RE: Binomial distribution in VMS - by Koen G - 21-08-2024, 08:17 PM
RE: Binomial distribution in VMS - by bi3mw - 22-08-2024, 07:59 PM
RE: Binomial distribution in VMS - by bi3mw - 23-08-2024, 11:24 PM
RE: Binomial distribution in VMS - by bi3mw - 25-08-2024, 12:23 AM
RE: Binomial distribution in VMS - by RobGea - 25-08-2024, 06:11 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 10:27 AM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 03:38 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 05:08 PM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 05:54 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 06:02 PM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 06:08 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 08:34 PM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 10:45 PM
RE: Binomial distribution in VMS - by bi3mw - 27-08-2024, 03:32 PM
RE: Binomial distribution in VMS - by RobGea - 27-08-2024, 09:41 PM
RE: Binomial distribution in VMS - by ReneZ - 27-08-2024, 10:57 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 01:28 PM
RE: Binomial distribution in VMS - by nablator - 28-08-2024, 02:17 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 03:03 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 06:04 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 06:25 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 08:06 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 08:19 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 10:02 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 10:44 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 10:53 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 11:02 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 11:12 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 11:52 PM
RE: Binomial distribution in VMS - by RobGea - 29-08-2024, 12:03 AM
RE: Binomial distribution in VMS - by bi3mw - 29-08-2024, 12:18 AM
RE: Binomial distribution in VMS - by bi3mw - 29-08-2024, 10:52 PM
RE: Binomial distribution in VMS - by bi3mw - 30-08-2024, 10:36 PM
RE: Binomial distribution in VMS - by RobGea - 06-09-2024, 08:08 PM
RE: Binomial distribution in VMS - by lelle - 06-09-2024, 09:47 PM
RE: Binomial distribution in VMS - by bi3mw - 07-09-2024, 02:24 AM
RE: Binomial distribution in VMS - by Koen G - 07-09-2024, 09:06 AM
RE: Binomial distribution in VMS - by bi3mw - 07-09-2024, 09:22 AM
RE: Binomial distribution in VMS - by ReneZ - 08-09-2024, 01:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)