I tried to implement a Generator expressions in Julia, but I run in an error which I do not know how to fix.
julia> using JSON
julia> path = "test.txt"
julia> JSON.parse(readline(open(path)))
Dict{String,Any} with 16 entries:
"nk" => 1
"cy" => "Danvers"
"c" => "US"
"hh" => "1.usa.gov"
"r" => "http://www.facebook.com/l/7AQEFzjSi/1.usa.gov/wfLQtf"
"a" => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like …
"h" => "wfLQtf"
"t" => 1331923247
"g" => "A6qOVH"
"tz" => "America/New_York"
"ll" => {42.576698,-70.954903}
"l" => "orofrog"
"hc" => 1331822918
"gr" => "MA"
"u" => "http://www.ncbi.nlm.nih.gov/pubmed/22415991"
"al" => "en-US,en;q=0.8"
julia> record = [JSON.parse(line) for line in eachline(open(path))]
ERROR: no method length(EachLine)
in anonymous at no file
You can't use list comprehensions with objects that have lengths that aren't known a priori. I think you need a while loop here.
I'm also not sure that you can use JSON parsing with line-oriented input, since JSON boundaries might occur across line boundaries.
If the file is not too big, you can use readlines instead of eachline because it returns an array, instead of a iterator (and arrays have a length method and can be used in comprehensions).
My favorite is the one you described in the comment:
using JSON
records = Dict{String,Any}[]
open(path,"r") do f
for line in eachline(f)
push!(records, JSON.parse(line))
end
end
Related
I am missing something obvious, but I can't see it
export const subjectSelector: MemoizedSelector<
any,
Subject[]
> = new EntitySelectorsFactory().create<Subject>('subject').selectEntities;
this.store.pipe(
select(entitySelectors.subjectSelector),
map((s:Subject) => return {...s, z: {}}),
filter((subject:Subject) => subject.z.evidence && subject.z.evidence.length > 0)
);
select(entitySelectors.subjectSelector) is returning an array of Subject objects, but the compiler complains
Type 'Subject' is missing the following properties from type 'Subject[]': length, pop, push, concat, and 28 more.
map((s:Subject) => return {...s, z: {}}),
What am I missing?
Seems like you are confusing list and Observable map() function. This works for me assuming selectEntities returns the Ngrx Entity type Dictionary. The Parenthteses are hell though:
this.store.pipe(select(subjectSelector),
map((subjects: Dictionary<Subject>) => Object.values(subjects).map(s => ({...s, z: {}}))));
if 'subjects' is just a plain array, this will do:
this.store.pipe(select(subjectSelector),
map((subjects: Subject[]) => subjects.map(s => ({...s, z: {}}))));
This section of my program is supposed to list all files within the directory containing ".txt" in the name but it's not returning anything when run. If I delete ".txt" and leave it as an empty string "" then it works perfectly and returns all file names including the .txt files so I can't figure out what I'm doing wrong here.
procedure Search_Directory is
use Ada.Directories;
procedure Write_Search_Item(Search_Item : in Directory_Entry_Type) is
begin
Put(Item => Simple_Name(Directory_Entry => Search_Item));
New_Line;
end Write_Search_Item;
Filter : Constant Filter_Type := (Ordinary_File => True,
Special_File => False,
Directory => True);
begin
Search(Directory => Current_Directory,
Pattern => (".txt"),
Filter => Filter,
Process => Write_Search_Item'Access);
end Search_Directory;
The Search function, defined in the package Ada.Directories, takes a pattern argument which is either a null string or a form that is implementation-defined RM A.16 (111/ 2). In GNAT, this pattern is supposed to be a regular expression (see also here) described in System.Regexp (see also here, second grammar, a "globbing pattern").
I'm trying to return string "<a>" , but I received empty string.
That is,
"<a>" => (nothing but not nil)
"PP<a>" => PP
"R".."<a>" => R
"R:" .. (string.format("<%s>", "a")) => R
I haven't found in documentation this feature.
Can you help my understand why this happens?
It might be because you're viewing it in an application where the HTML tags are parsed. You'd need to escape the < and > characters:
"<a>"
I've been using Ada.Containers.Indefinite_Hased_Maps to create my own custom hashed maps, and it worked quite well until I tried to use a vector as the element type. Here is an example of the problematic code:
package String_Vectors is new Ada.Containers.Vectors(Element_Type => Unbounded_String, Index_Type => Natural);
subtype String_Vector is String_Vectors.Vector;
package Positive2StringVector_HashMaps is new Ada.Containers.Indefinite_Hashed_Maps --Compiler fails here
(Element_Type => String_Vector,
Key_Type => Positive,
Hash => Positive_Hash,
Equivalent_Keys => Positive_Equal);
Basically, I cannot Positive2StringVector_HashMaps package, because the compiler comes up with:
no visible subprogram matches the specification for "="
From what I understand, it isn't finding the equality operator for the String_Vector , am I correct? If I am, what is the proper way of implementing it? And if I'm not, what am I doing wrong??
You don’t need to implement
function “=“ (L, R : String_Vectors.Vector) return Boolean
yourself, because there already is one in String_Vectors; see ALRM A.18.2(12). So you write
package Positive2StringVector_HashMaps is new Ada.Containers.Indefinite_Hashed_Maps
(Element_Type => String_Vector,
Key_Type => Positive,
Hash => Positive_Hash,
Equivalent_Keys => Positive_Equal,
“=“ => String_Vectors.”=");
By the way, is there some reason you used Ada.Containers.Vectors on Unbounded_String rather than Indefinite_Vectors on String? (wanting to change the length of a contained string would count as a Good Reason!)
This represents what I want, but which doesn't work:
syntax
"_F_hex" :: "any => any" ("F;")
translations
"F;" => "True,True,True,True"
I would use F; like this:
[F;,F;] == [True,True,True,True,True,True,True,True]
Isabelle must be able to parse the right-hand side of a translation, but True,True,... does not yield a valid syntax tree. If you use F; only in list enumerations, you can extend the syntax translation rules for list enumerations as follows.
syntax "_F_hex" :: "logic" ("F;")
translations
"[F;, xs]" => "CONST True # CONST True # CONST True # CONST True # [xs]"
"[F;]" => "CONST True # CONST True # CONST True # CONST True # []"
Note that _F_hex does not take any argument, so its "type" is logic (and not something of the form _ => _) which stands for a parse tree node for a term. In the translations, you have to mark constants in the logic such as True with CONST. Otherwise, Isabelle would treat True as a variable.