Rosetta Code/Count examples: Difference between revisions

m
→‎{{header|Ada}}: Adjust to Rosetta/Find unimplemented task
m (Ada : simplified code)
m (→‎{{header|Ada}}: Adjust to Rosetta/Find unimplemented task)
Line 11:
Total: X examples.</lang>
=={{header|Ada}}==
{{libheader|AWS}}
Libraries : Ada Web server (AWS) and XMLAda from AdaCore
Parsing XML file with XMLAda from AdaCore
<lang Ada>with AWS.Response; use AWS.Response;
<lang Ada>with Aws.Client, Aws.Messages, Aws.Response, Aws.Resources, Aws.Url;
with AWS.Resources; use AWS.Resources;
with Dom.Readers, Dom.Core, Dom.Core.Documents, Dom.Core.Nodes, Dom.Core.Attrs;
with AWS.Messages; use AWS.Messages;
with Input_Sources.Strings;, Unicode, use Input_SourcesUnicode.Ces.StringsUtf8;
with AWS.URL;
with Ada.Strings.Unbounded;, Ada.Strings.Fixed, useAda.Text_IO, Ada.Strings.UnboundedCommand_Line;
with DOM.Readers; use DOM.Readers;
with DOM.Core; use DOM.Core;
with DOM.Core.Documents; use DOM.Core.Documents;
with DOM.Core.Nodes; use DOM.Core.Nodes;
with DOM.Core.Attrs; use DOM.Core.Attrs;
with AWS.Client; use AWS.Client;
with Input_Sources.Strings; use Input_Sources.Strings;
with Unicode;
with Unicode.CES.Utf8;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO, Ada.Strings.Fixed;
with Ada.Containers.Vectors;
use Ada, AWS;
 
use Aws.Client, Aws.Messages, Aws.Response, Aws.Resources, Aws.Url;
procedure Count_examples is
use Dom.Readers, Dom.Core, Dom.Core.Documents, Dom.Core.Nodes, Dom.Core.Attrs;
use Aws, Ada.Strings.Unbounded, Ada.Strings.Fixed, Input_Sources.Strings;
withuse Ada.Text_IO, Ada.Strings.FixedCommand_Line;
 
procedure Count_examplesCount_Examples is
package Exemple_Vectors is new Containers.Vectors (
 
package Exemple_VectorsMembers_Vectors is new Ada.Containers.Vectors (
Index_Type => Positive,
Element_Type => Unbounded_String);
use Exemple_VectorsMembers_Vectors;
 
Exemples : Vector;
Nbr_Lg, Total : Natural := 0;
 
procedure Get_ListGet_Vector (Category : in String; Mbr_Vector : in out Vector) is
Reader : Tree_Reader;
Doc : Document;
Line 46 ⟶ 40:
N : Node;
A : Attr;
Page : AWSAws.Response.Data;
URI_XMLUri_Xml : constant String :=
"http://rosettacode.org/mw/api.php?action=query&list=categorymembers&"
&
"cmtitle&format=Category:Programming_Tasksxml&cmlimit=500&formatcmtitle=xmlCategory:";
begin
Page := Client.Get (URI_XMLUri_Xml & Category);
if Response.Status_Code (Page) not in Messages.Success then
raise Client.Connection_Error;
end if;
declare
XMLXml : constant String := Message_Body (Page);
Source : String_Input;
begin
Open
(XMLXml'Unrestricted_Access,
Unicode.CESCes.Utf8.Utf8_Encoding,
Source);
Parse (Reader, Source);
Line 72 ⟶ 66:
N := Item (List, Index - 1);
A := Get_Named_Item (Attributes (N), "title");
Append (ExemplesMbr_Vector, To_Unbounded_String (Value (A)));
end loop;
Free (List);
Free (Reader);
end Get_ListGet_Vector;
 
function Scan_Page (Title : String) return Natural is
Page : AWSAws.Response.Data;
File : AWSAws.Resources.File_Type;
Buffer : String (1 .. 1024);
Languages, Position, Last : Natural := 0;
Line 87 ⟶ 81:
Client.Get
("http://rosettacode.org/mw/index.php?title=" &
AWSAws.URLUrl.Encode (Title) &
"&action=raw");
Response.Message_Body (Page, File);
Line 93 ⟶ 87:
Resources.Get_Line (File, Buffer, Last);
Position :=
Strings.Fixed.Index
(Source => Buffer (Buffer'First .. Last),
Pattern => "=={{header|");
Line 105 ⟶ 99:
 
begin
Get_Vector ("Programming_Tasks", Exemples);
Get_List;
 
for I in First_Index (Exemples) .. Last_Index (Exemples) loop
declare
Title : constant String :=
To_String (Exemple_VectorsMembers_Vectors.Element (Exemples, I));
begin
Nbr_Lg := Scan_Page (Title);
Total := Total + Nbr_Lg;
Text_IO.Put_Line (Title & " :" & Integer'Image (Nbr_Lg) & " exemples.");
(Title & " :" & Integer'Image (Nbr_Lg) & " exemples.");
end;
end loop;
 
Text_IO.Put_Line ("Total :" & Integer'Image (Total) & " exemples.");
end Count_examplesCount_Examples;
</lang>
Output :
<lang>$>count_examples
<pre>
100 doors : 107 exemples.
24 game : 2930 exemples.
.....
24 game/Solve : 20 exemples.
99 Bottles of Beer : 124 exemples.
.....
Yahoo! search interface : 10 exemples.
Zig-zag matrix : 49 exemples.
Total : 1715817238 exemples.</pre>
</lang>
 
=={{header|AutoHotkey}}==
Anonymous user