Am I using Pluralizer wrong? - asp.net-mvc-3

Paging Jay Querido...
Downloaded the Pluralizer NuGet package. My goal is to display a string like so:
X contracts with Y partners in Z countries
If X is 1, word should change to contract. If Z is 1, word should change to country. Same for 1 partner.
The following does not work. It always results in TotalContracts being the same number for the whole sentence.
#Html.Pluralize("{_} {contract} with {_} {partner} in {_} {country}",
Model.TotalContracts, Model.TotalPartners, Model.TotalCountries)
#* result is X contracts with X partners in X countries *#
The following does work, but is not quite as readable. Is there a better way?
#Html.Pluralize("{_} {contract}", Model.TotalContracts) with
#Html.Pluralize("{_} {partner}", Model.TotalPartners.Count) in
#Html.Pluralize("{_} {country}", Model.TotalCountries)

It looks like my comment obscured an underscore. This works with a single call to Pluralize:
#Html.Pluralize("{0|_} {0|contract} with {1|_} {1|partner} in {2|_} {country}",
Model.TotalContracts, Model.TotalPartners, Model.TotalCountries)

Related

Pattern matching using list of characters

I am having difficulty pattern matching words which are converted to lists of characters:
wordworm(H1,H2,H3,V1,V2) :-
word(H1), string_length(H1,7),
word(H2), string_length(H2,5),
word(H3), string_length(H3,4),
word(V1), string_length(V1,4),
word(H3) \= word(V1),
atom_chars(H2, [_,_,Y,_,_]) = atom_chars(V1, [_,_,_,Y]),
word(V2), string_length(V2,5),
word(H2) \= word(V2),
atom_chars(H3, [_,_,_,Y]) = atom_chars(V2, [_,_,_,_,Y]).
Above this section, I have a series of 600 words in the format, word("prolog"). The code runs fine, without the atom_chars, but with it, I get a time-out error. Can anyone suggest a better way for me to structure my code?
Prolog predicate calls are not like function calls in other languages. They do not have "return values".
When you write X = atom_chars(foo, Chars) this does not execute atom_chars. It builds a data structure atom_chars(foo, Chars). It does not "call" this data structure.
If you want to evaluate atom_chars on some atom H2 and then say something about the resulting list, call it like:
atom_chars(H2, H2Chars),
H2Chars = [_,_,Y,_,_]
So overall maybe your code should look more like this:
...,
atom_chars(H2, H2Chars),
H2Chars = [_,_,Y,_,_],
atom_chars(V1, V1Chars),
V1Chars = [_,_,_,Y],
...
Note that you don't need to assert some kind of "equality" between these atom_chars goals. The fact that their char lists share the same variable Y means that there will be a connection: The third character of H2 must be equal to the fourth character of V1.

How to exclude all countries that have flag with primary colour in prolog?

I have a set of facts on prolog as follows:
primary(red).
primary(blue).
primary(yellow).
flag(france,red).
flag(france,blue).
flag(france,white).
flag(china,red).
flag(china,white).
flag(india,orange).
flag(india,green).
flag(india,white).
i want to run a query to return a list of countries whose flag does not contain primary colour at all. In the case of my program it should return india only.
i tried the following code, but it did not work:
?- flag(X,Y),not(primary(Y)).
X = france,
Y = white ;
X = china,
Y = white ;
X = india,
Y = orange ;
X = india,
Y = green ;
X = india,
Y = white.
The problem in the result is that the flag of france contains primary colour. But it is returning france because it also has a non primary colour in its flag. so is the case for china.
Thank you.
The way Prolog answers to a query doesn't allow you to do this. Whatever the query is, Prolog will go through the list of predicate one by one. With your predicates, Prolog has no way to know if flag(china,white) (for example) is the last one attributing a color to the chinese flag, thus you cannot select the flags that don't have a specific color.
A way to go around this problem is to use list to store the colors of a flag :
flag(france,[red,blue,white]).
flag(china,[red,white]).
flag(india,[orange,green,white]).
This way, Prolog just go through the list to know if there is a primary color or not.
Here is an example of function that does what you want :
no_primary_color(X,[]).
no_primary_color(X,[C|Cs]) :- not(primary(C)),no_primary_color(X,Cs).
And the query :
?- flag(X,Y), no_primary_color(X,Y).
The query you posted asks something like "what countries have colors in their flag that are not primary colors?". As you noticed, this is not exactly what you want.
If you want to use negation, you must first express exactly the predicate that you then want to negate. You ask for "countries whose flag does not contain primary colour". So let's first express the notion of "countries whose flag does contain a primary color"!
country_primarycolor(Country, Color) :-
flag(Country, Color),
primary(Color).
Let's see if this does what we want:
?- country_primarycolor(Country, Color).
Country = france,
Color = red ;
Country = france,
Color = blue ;
Country = china,
Color = red ;
false.
For the next step we also need to be able to express the notion of "country". This is easy:
country(france).
country(china).
country(india).
And now, countries whose flag does not contain primary colors:
?- country(Country), not(country_primarycolor(Country, _Color)).
Country = india.

Power Query - Multiple OR statement with values

I've been doing research on this and I find a plethora of articles related to Text, but they don't seem to be working for me.
To be clear this formula works, I'm just looking to make it more efficient. My formula looks like:
if [organization_id] = 1 or [organization_id] = 2 or [organization_id] = 3 then "North" else if … where organization_id is of type "WholeNumber"
I'd like to simplify this by doing something like:
if [organization_id] in {1, 2, 3} then "North" else if …
I've tried wrapping in Parenthesis, Braces, & Brackets. Nothing seems to work. Most articles are using some form of text.replace function and mine is just a custom column.
Does MCode within Power Query have any efficiencies like this or do I have to write out each individual statement like the first line?
I've had success with the a List.Contains formulation:
List.Contains({1,2,3}, [organization_id])
The above checks if [organization_id] is in the list supplied in the first argument.
In some cases, you may not want to hardcode a list as shown above but reference a table column instead. For example,
List.Contains(TableWithDesiredIds[id_column], [organization_id])

SWI-Prolog list result

I'm coding in prolog, but I have a issue. How can I make that the answer appears just once? for example I just want that "X = uni, X = uca, X = unam" but instead it just keep showing me the options repeatedly.
This is some of it:
is(uni, college).
is(uca, college).
is(unan, college).
is(computation, carrer).
In this part I'm assigning available places to the carrer
has(computation, available_places, 200).
and finally assigning the carrer to a college
offers(unan, computation).
offers(uni, computation).
offers(uca, computation).
and I make the query like this:
which(X):- is(X, college), is(Y, carrer), offers(X, Y),has(Y, available_places, Z), Z<300.
but the result as I said at the beggining, show me the names of the college repeadtedly. Any idea how to solve this? D:

Prolog knowledge query

% A quiz team structure takes the form:
% team(Captain, Vice_captain, Regular_team_members).
% Captain and Vice_captain are player structures;
% Regular_team_members is a list of player structures.
% player structures take the form:
% player(First_name, Surname, details(Speciality,Recent_score)).
team(player(niall,elliott,details(history,11)),
player(michelle,cartwright,details(fashion,19)),
[player(peter,lawlor,details(science,12)),
player(louise,boyle,details(current_affairs,17))]).
I've been given the database above (I haven't copied over all the entries of people as it would be too long).
I've been asked to get the surname of any vice-captain whose team includes a captain or a regular team member whose speciality is science.
I can get the surname of the vice-captains using the code below but I can't return only those teams that include a captain or regular team members whose speciality is science. What would I need to add to do this?
part_two(Surname):-
team(_,player(_,Surname,_),_).
I've also been asked to also get the first name and the surname of any captain whose regular team members number more than one and who all have the same surnames.
This is my attempt so far:
part_three(First_name,Surname):-
team(Captain,_,Regular_team_members),
first_name(Captain,First_name),
surname(Captain,Surname),
Regular_team_members=[_,_|_].
I just need to exclude the details of those captains whose regular team members don't all have the same surname.
part_two(Surname):-
team(Captain, Vice_captain, Regular_team_members),
surname(Vice_captain, Surname),
member(Player, [Captain|Regular_team_members]),
specialty(Player, science).
% 'abstract data structures' accessors
surname(player(_First_name, Surname, _Details), Surname).
specialty(player(_First_name, _Surname, details(Speciality, _Recent_score)), Speciality).
Since you're going anyway to scan the Regular_team_members list, looking for appropriate constraint, you can get a simpler 'program' first 'joining' the Captain to other players.
You could change a little what you have already written as follows:
part_two(Surname):-
team(P,player(_,Surname,_),L),
( P=player(_,_,details(science,_)) -> true ; member(player(_,_,details(science,_)),L) ).
Example:
Database:
team(player(niall,elliott,details(history,11)),
player(michelle,cartwright,details(fashion,19)),
[player(peter,lawlor,details(history,12)),
player(louise,boyle,details(current_affairs,17))]).
team(player(niall1,elliott1,details(science,11)),
player(michelle1,cartwright1,details(fashion,19)),
[player(peter,lawlor,details(history,12)),
player(louise,boyle,details(current_affairs,17))]).
team(player(niall2,elliott2,details(history,11)),
player(michelle2,cartwright2,details(fashion,19)),
[player(peter,lawlor,details(science,12)),
player(louise,boyle,details(current_affairs,17))]).
team(player(niall3,elliott3,details(science,11)),
player(michelle3,cartwright3,details(fashion,19)),
[player(peter,lawlor,details(science,12)),
player(louise,boyle,details(current_affairs,17))]).
Now querying:
?- part_two(X).
X = cartwright1 ;
X = cartwright2 ;
X = cartwright3.

Resources