Create an ordered set in F# - f#

I need some help to find out how to create an ordered set in F#, or at least create a set and then order it. Documentation on the topic is not very clear.

Set implements IEnumerable interface so you can use functions from Seq module on sets.
let set = Set.ofList [ 9; 2; 5; 7; 5 ]
let orderedSeq = Seq.sort set
By design Set is something that is not excatly sorted collection but you can query to the set to retrive its elements in specific order.

Related

In Jena API, How to count how many individuals of a class using Jena RULE?

I want to get how many individuals of a class. For example, for the Person class, there is A, B, C. I tried to count it using the following rule:
[r3: (?p rdf:type hv:Person),(?classx1 hv:hasvalue ?n),addOne(?n,?new)
-> drop(1),(?class1 hv:hasvalue ?new)
]
However, it was fired in a closed loop since the (?class1 hv:hasvalue ?new) will change each time. I dont like to introduce SPARQL.
What I do to count individuals is :
OntModel model;
Resource individual = model.getResource("http://www.w3.org/2002/07/owl#NamedIndividual"));
Property property = model.getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
ResIterator iterator = infModel.listResourcesWithProperty(property, individual) ;
int count = Iterators.size(iterator);
Last line is possible because of Guava Library.
It can be improved but still a solution.
More information and corrections in the comments. Thanks to #ssz.

Add Integer Number to existing Values - Neo4j

Using Neo4j.
I would like to add a integer number to values already existing in properties of several relationships that I call this way:
MATCH x=(()-[y]->(s:SOL{PRB:"Taking time"})) SET y.points=+2
But it doesn't add anything, just replace by 2 the value I want to incremente.
To achieve this use
SET y.points = y.points + 2
From your original question it looks like you were trying to use the Addition Assignment operator which exists in lots of languages (e.g. python, type/javascript, C#, etc.). However, in cypher += is a little different and is designed to do this in a way which allows you to add or update properties to or on entire nodes or relationships based on a mapping.
If you had a parameter like the below (copy this into the neo4j browser to create a param).
:param someMapping: {a:1, b:2}
The query below would create a property b on the node with value 2, and set the value of property a on that node to 1.
MATCH (n:SomeLabel) WHERE n.a = 0
SET n+= $someMapping
RETURN n

How to Add Compound Indices in Shark Orm

I understand how to define one property indices in SharkORM per the documentation
+ (SRKIndexDefinition *)indexDefinitionForEntity {
SRKIndexDefinition* idx = [SRKIndexDefinition new];
[idx addIndexForProperty:#"name" propertyOrder:SRKIndexSortOrderAscending];
[idx addIndexForProperty:#"age" propertyOrder:SRKIndexSortOrderAscending];
return idx;
}
From my understanding the above will create one index on name, and another on age. However, what if I want to create a compound index (i.e. one that encompasses name first, and then age). If the above code is doing that, then my question is instead how do I define more than one index for a model?
To put it another way how would I define the following two indices in SharkORM?
[name, age]
[name, location]

Data structures in Rascal

I am looking for a data structure that can mimic an Object or a struct. Really, just some compact way to pass around different types of variables. Currently I am using a tuple but referencing various parts of the tuple is less pleasant than I would like. Currently I've just created aliases that represent the various locations in the tuple:
alias AuxClass = tuple[str,str,list[int],list[int],Dec];
int ACLS = 0;
But I've had to restructure this tuple and thus had to change the indexing. Is there something I can use here that I've missed or perhaps a feature coming in the future?
Thanks!
Please take a look at the algebraic data types feature:
http://tutor.rascal-mpl.org/Rascal/Rascal.html#/Rascal/Declarations/AlgebraicDataType/AlgebraicDataType.html
You can create a constructor to represent the type of data that you are trying to define above, similar to what you would do with a struct, and give each element in the constructor a field name:
data AuxClass = auxClass(str f1, str f2, list[int] f3, list[int] f4, Dec f5)
You can then create new instances of this just using the constructor name and providing the data:
a = auxClass("Hello", "World", [1,2,3], [4,5,6], D1) (where D1 is a Dec).
Once you have an instance, you can access information using the field names:
a.f1 // which equals "Hello"
a.f3 // which equals [1,2,3]
size(a.f3) // which currently equals 3
and you can update information using the field names:
a.f2 = "Rascal"
a.f4 = a.f4 + 7 // f4 is now [4,5,6,7]
Algebraic data types are actually quite flexible, so there is a lot you can do with them beyond this. Feel free to look through the documentation and ask questions here.

How to create modifiable dart array

I want to create a buffer that can appended things.
For example
var allInput = new Uint8List(1);
allInput.add(list)
But it's informed me that this is can not be modify.
Per the API docs, Uint8List is a fixed list. You could use code such as:
var allInput = new Uint8List(1);
allInput[0] = 123;
If you want a growable list, you could do something like:
var allInput = new List();
allInput.addAll(list);
or
var allInput = new List<int>();
allInput.addAll(list);
Essentially, if you provide a size specifier when creating a list, that makes it fixed size. Otherwise it's extendable (ref)
What Chris writes in his answer is correct today, but starting soon, the generic List constructor will not be fixed length when a length argument is given. The list’s size will still be changeable afterwards. There will also be a couple of additional named constructors for List:
factory List.fixedLength(int length, {E fill: null})
factory List.filled(int length, E fill)
these will help with constructing fixed length lists and creating lists with pre-filled values.
For details on bleeding edge changes to List, see:
http://api.dartlang.org/docs/bleeding_edge/dart_core/List.html

Resources