locked
count times each category exist in string RRS feed

  • Question

  • I want to count times each category exist in string

    Like the one 

    http://www.acm.org/about/class/ccs98-html

    the main problem is that word Like General appear more than once

    and each general may or may not have sub categories

    i want to count how many times each category come .

    I needed ASAP.

    Regards


    faheem


    • Edited by FaheemKhan Monday, September 24, 2012 11:22 AM
    Monday, September 24, 2012 11:00 AM

Answers

  • maybe not! Because it count only occurrence.

    In my opinion there isn't a shortest path or better, BNF is the shortest path if you don't have a xml or similar data structures.

    For example, the webpage (proglang-04.html) has a xhtml structures and you can try to parse it in xml document. After that you can analyze the XDocument to linq.

    Observe:

    String xml_docs = @"<?xml version=""1.0"" encoding=""UTF-8""?>  
    <emails> 
        <emailAddress>jdoe@set.ca</emailAddress> 
        <emailAddress>jsmith@hit.ca</emailAddress> 
        <emailAddress>rgreen@set_ig.ca</emailAddress>  
    </emails>";
    
    
    XDocument doc = XDocument.Parse(xml_docs); 
     
    var emailAddresses = (from emails in doc.Descendants("emailAddress") 
                          select emails.Value); 
     
    foreach (var email in emailAddresses) 
    { 
        //Comment out if using WPF or Windows Form project 
        Console.WriteLine(email.ToString()); 
     
       //Remove comment if using WPF or Windows Form project 
       //MessageBox.Show(email.ToString()); 
    } 
    

    Monday, September 24, 2012 1:32 PM

All replies

  • Can you explain better what kind of 'source' do you have? For example, do you have xml file or a flat string?

    Monday, September 24, 2012 11:09 AM
  • I have string.


    faheem

    Monday, September 24, 2012 11:21 AM
  • in that case, there isn't 'good answer' for all situations, because you are in a bad situation : context-dependence.

    In general you have to define a BNF (a grammar) that represent your hypothetical language (see: http://www.cse.chalmers.se/edu/year/2011/course/TIN321/lectures/proglang-04.html) and you need to implement a lexer/parser that will produce structural entities. (see theory of programming language)

    Monday, September 24, 2012 11:51 AM
  • I agree

    But it's very long way to do it.

    I wanted a shortest path


    faheem

    Monday, September 24, 2012 12:17 PM
  • Is it possible to have regular expressions  for it.


    faheem

    Monday, September 24, 2012 12:45 PM
  • maybe not! Because it count only occurrence.

    In my opinion there isn't a shortest path or better, BNF is the shortest path if you don't have a xml or similar data structures.

    For example, the webpage (proglang-04.html) has a xhtml structures and you can try to parse it in xml document. After that you can analyze the XDocument to linq.

    Observe:

    String xml_docs = @"<?xml version=""1.0"" encoding=""UTF-8""?>  
    <emails> 
        <emailAddress>jdoe@set.ca</emailAddress> 
        <emailAddress>jsmith@hit.ca</emailAddress> 
        <emailAddress>rgreen@set_ig.ca</emailAddress>  
    </emails>";
    
    
    XDocument doc = XDocument.Parse(xml_docs); 
     
    var emailAddresses = (from emails in doc.Descendants("emailAddress") 
                          select emails.Value); 
     
    foreach (var email in emailAddresses) 
    { 
        //Comment out if using WPF or Windows Form project 
        Console.WriteLine(email.ToString()); 
     
       //Remove comment if using WPF or Windows Form project 
       //MessageBox.Show(email.ToString()); 
    } 
    

    Monday, September 24, 2012 1:32 PM