YetAnotherPacketParser 1.4.0

dotnet add package YetAnotherPacketParser --version 1.4.0
                    
NuGet\Install-Package YetAnotherPacketParser -Version 1.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YetAnotherPacketParser" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YetAnotherPacketParser" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="YetAnotherPacketParser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YetAnotherPacketParser --version 1.4.0
                    
#r "nuget: YetAnotherPacketParser, 1.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package YetAnotherPacketParser@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YetAnotherPacketParser&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=YetAnotherPacketParser&version=1.4.0
                    
Install as a Cake Tool

Yet Another Packet Parser

Introduction

Yet Another Packet Parser (YAPP) is a parser for quiz bowl packets written in C#. Some of its features are

  • Converts packets in a docx or HTML file to JSON or HTML
  • MODAQ can read the JSON packets it outputs
  • Can convert each packet in a zip file
  • Specific error messages that give a line number and text near where the parser failed

You can try out a simple demo of the parser here.

Usage

Command-line program

The command line program takes in a docx file and writes it to another file (by default, JSON)

YetAnotherPacketParserCommandLine.exe -i C:\qbsets\packet1.docx -o C:\qbsets\packet1.json

If you want to output it to an HTML file, set the format to html

YetAnotherPacketParserCommandLine.exe -i C:\qbsets\packet1.docx -o C:\qbsets\packet1.json -f html

To write the packet in the yapp2 format, set the format to yapp2

YetAnotherPacketParserCommandLine.exe -i C:\qbsets\packet1.docx -o C:\qbsets\packet1.json -f yapp2

To see the list of all flags, run

YetAnotherPacketParserCommandLine.exe --help

Library

YAPP comes with a C# library that is consumable through Nuget. You need to get the stream to the file and set the right compiler options, then call PacketConverter.ConvertPackets. For example, to convert a packet to HTML, you can use something like

IPacketConverterOptions packetCompilerOptions = new HtmlPacketCompilerOptions()
{
    StreamName = "packet1.html",
    PrettyPrint = options.PrettyPrint
};

IEnumerable<ConvertResult> results;
using (FileStream fileStream = new FileStream("C:\\qbsets\\packet1.docx", FileMode.Open, FileAccess.Read, FileShare.Read))
{
    results = await PacketConverter.ConvertPacketsAsync(fileStream, packetCompilerOptions);
}

ConvertResult compileResult = outputResults.First();
if (!compileResult.Result.Success)
{
    Console.Error.WriteLine(compileResult.Result);
    return;
}

File.WriteAllText(options.Output, compileResult.Result.Value);

Note that the method can take in a zip file too, and it will return all of the packets it attempted to parse.

yapp2

yapp2 is a backwards-compatible superset of the JSON YAPP writes. It carries things plain JSON packets cannot: which words a pronunciation guide covers, and the rules of the game the packet is written for. Set Yapp2Format on JsonPacketCompilerOptions (or pass -f yapp2 on the command line, or ?format=yapp2 to the API) to write it.

The format is specified in YAPP2_FORMAT.md. A yapp2 packet is the same packet, plus

  • a top-level "version": "yapp2/1.4",
  • an anchored object on any question that has an anchor, holding every text field of the question again with <pg> tags around the anchored words, and a canonicalHash of the plain text it was made from, and
  • a top-level gameFormat object, when you give YAPP one.
{
  "version": "yapp2/1.4",
  "tossups": [
    {
      "number": 1,
      "question": "Denis Diderot (\"DID-er-OW\") edited this work.",
      "answer": "<b><u>Encyclopédie</u></b>",
      "anchored": {
        "question": "Denis <pg>Diderot</pg> (\"DID-er-OW\") edited this work.",
        "answer": "<b><u>Encyclopédie</u></b>",
        "canonicalHash": "d9faa5084611cecf01eef6236bc2a5ae4806c3f882592ee709d6ea94edfb43fa"
      }
    }
  ]
}

The canonical fields are byte-for-byte what YAPP writes without yapp2, and the tag only ever appears in anchored, so a reader that has never heard of yapp2 reads a yapp2 packet correctly and ignores the extra fields. anchored is left off entirely when a question has no anchors, which is most of them. A packet with no anchors and no game format is written as plain JSON, with no version, since it has nothing yapp2 to say.

canonicalHash is there because packets get edited by hand after they're parsed. If someone fixes a typo in question and leaves anchored alone, the hash no longer matches, and a reader knows to fall back to the canonical text rather than undo the fix. YAPP2_FORMAT.md gives the exact algorithm.

The anchored words are ordinary question words: they are read aloud, they count toward word counts, and they are buzzable. The guide itself is none of those things.

Where anchors come from

YAPP finds an anchor in a .docx file by looking for colored text that a pronunciation guide immediately follows. Authoring tools tint the anchored words so a writer can see what a guide is attached to, and that tint is what YAPP reads.

Colored text with no guide after it is left alone, so coloring text for any other reason does not turn it into an anchor - and neither does a grayed-out guide, which is colored text that follows nothing. The guide has to start within about three characters of the anchor, so a parenthetical later in the sentence isn't mistaken for one, and a power marker (*) doesn't count as a guide because it has no letters in it.

In an HTML file, wrap the anchored words in a <pg> tag instead. The tag is explicit, so it is an anchor whether or not a guide follows it.

Game format

A packet doesn't say how many tossups are in regulation or what a power is worth, so readers have had to set the game up by hand. Give YAPP the format and it writes a gameFormat object into each packet:

YetAnotherPacketParserCommandLine.exe -i C:\qbsets\packet1.docx -o C:\qbsets\packet1.json -f yapp2 -g macf

"gameFormat": {
  "displayName": "mACF with powers",
  "regulationTossupCount": 20,
  "minimumOvertimeQuestionCount": 1,
  "overtimeIncludesBonuses": false,
  "powers": [{ "marker": "(*)", "points": 15 }],
  "negValue": -5,
  "bonusesBounceBack": false,
  "timeoutsAllowed": 1,
  "tossupsOnly": false,
  "pronunciationGuideMarkers": ["(\"", "\")"]
}

-g takes one of the named formats below, or the path to a JSON file with your own. A file only needs the rules you want to set; anything left out is left to the reader. Superpowers are just more than one entry in powers:

{ "regulationTossupCount": 24, "powers": [{ "marker": "(+)", "points": 20 }, { "marker": "(*)", "points": 15 }] }
Name Regulation tossups Powers Negs Bonuses bounce back
acf 20 none -5 no
macf 20 (*) = 15 -5 no
pace 20 (*) = 20 none no

The API takes the named formats as ?format=yapp2&gameFormat=pace, and in code you set GameFormat on JsonPacketCompilerOptions (GameFormat.TryGetPreset("pace", out GameFormat? format) gets a named one). The field names match MODAQ's game format. Powers are named by their marker rather than by word position, since the marker is already in the question text. YAPP logs a warning when a format's power marker isn't in any of the packet's tossups, or when the packet has fewer tossups than the format's regulation count, since either usually means the wrong format was picked.

yapp2 1.1 also defines an optional readingOrder for packets whose tossups and bonuses interlace. YAPP never writes it: it reads all of a document's tossups and then all of its bonuses, so a packet it produces is always in the default order, which is exactly what leaving the field out means.

Development

Requirements:

  • .Net 6 SDK
    • If using Visual Studio, you need at least Visual Studio 2017.5
    • Nuget packages should be automatically downloaded by running dotnet build or through dotnet restore
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 100 11/14/2026
1.3.1 179 2/27/2026
1.3.0 141 2/9/2026
1.2.1 309 6/16/2024
1.2.0 229 3/12/2024
1.1.1 253 12/23/2023
1.1.0 284 6/23/2023
1.0.1 302 4/15/2023
1.0.0 638 4/18/2022
0.4.2 486 11/30/2021
0.4.1 549 11/14/2021
0.4.0 514 11/12/2021
0.3.0 599 10/10/2021
0.2.3 631 7/10/2021
0.2.1 556 3/21/2021
0.2.0 530 2/15/2021
0.1.1 532 1/17/2021
0.1.0 532 1/16/2021