Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this ought to help:</p> <pre><code>using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; class Production { public string Name; public string[] Components; public static IEnumerable&lt;Production&gt; Parse(string contents) { var rdr = new System.IO.StringReader(contents); string line; var productions = new List&lt;Production&gt;(); while(null != (line = rdr.ReadLine())) { if(string.IsNullOrEmpty(line)) continue; productions.Add(ParseOne(line)); } return productions; } public static Production ParseOne(string line) { var parts = line.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries); return new Production{Name = parts[0], Components = parts.Skip(2).ToArray()}; } } </code></pre> <p>You can use the Production.Parse method like so:</p> <pre><code>static void Main() { var productions = Production.Parse(@"S -&gt; NP VP S -&gt; Aux NP VP NP -&gt; Proper-Noun NP -&gt; Nominal Nominal -&gt; Noun Nominal -&gt; Nominal Noun Nominal -&gt; Nominal PP VP -&gt; Verb NP VP -&gt; Verb NP PP PP -&gt; Preposition NP"); // Or from a file like this: productions = Production.Parse(File.ReadAllText("myProductions.txt)); } </code></pre> <p><strong>Edit:</strong> To join the productions, consider <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.groupby.aspx" rel="nofollow">grouping by</a> Name.</p> <pre><code>productions.GroupBy(p =&gt; p.Name, p =&gt; new Production{Name=p.Key, Components=p.SelectMany(x =&gt; x)}); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload