library to query major clojure repos - maven

Is there a clojure library, that provides functions for querying the major clojure repositories (like clojars and maven central)? I was thinking of something like this:
(query-repos "reage")
=> {reagent ("0.6.0-SNAPSHOT" "0.6.0-rc" "0.6.0-alpha2" ...)
reagent-forms ("0.5.25" ...)}
In clj-ancient there is the function version-string!, which however seems to work only if the correct artifact name is given. (like 'reagent)

It looks like clojars has an API. The below should be enough to get started. Just require clj-http.
(defn get-release
[lib]
(let [url (str "https://clojars.org/api/artifacts/" lib)
resp (:body (clj-http.client/get url {:accept :edn}))
info (clojure.edn/read-string resp)]
(println "Name: " (:jar_name info) "\nLatest release: " (:latest_release info))))
user=> (get-release "reagent")
Name: reagent
Latest release: 0.6.0-rc
I realize now that you may be only looking for a way to do a partial match since you may not know the full repo name, so maybe this does not answer your question, but it may help others so I'll leave it. The link above has information on full listings which are in plain text and could easily be parsed and you could find partial matches easily this way.

Related

Complex combination of AND and OR in strapi (version 4) filtering

Hi I want to apply a filter to the strapi api with a combination of AND and OR but I can't seem to get it working.
Situation:
I want to filter on a situation like this
(
(tag OR tag2 OR tag3) AND
(
(title CONTAINSI TEXT_FILTER_HERE) OR
(body CONTAINSI TEXT_FILTER_HERE) OR
(introduction CONTAINSI TEXT_FILTER_HERE)
)
)
(note that I have abbreviated the tags as that should also be a containsi)
I have tried something like the link below and many others, but this example below will make all of them an OR situation, and I will find too many entries.
{{host}/api/blog?sort=publishedAt%3Adesc
&populate=Tags.tags&populate=Image
&pagination[page]=1
&pagination[pageSize]=25
&locale=en
&filters[$or][4][Tags][tags][Tag][$containsi]=TAG1
&filters[$or][6][Tags][tags][Tag][$containsi]=TAG2
&filters[$or][8][Tags][tags][Tag][$containsi]=TAG3
&filters[$or][3][Tags][tags][Tag][$containsi]=TAG4
&filters[$or][5][Tags][tags][Tag][$containsi]=TAG5
&filters[$or][7][Tags][tags][Tag][$containsi]=TAG6
&filters[$or][0][title][$containsi]=FILTER_TEXT_HERE
&filters[$or][2][body][$containsi]=FILTER_TEXT_HERE
&filters[$or][1][introduction][$containsi]=FILTER_TEXT_HERE
(made it multiline for readability)
Is it possible to this in strapi?
I can get it to work in an multiple OR situation with just one (1) AND, but not with ((or or) AND (or or)):
...
&filters[$or][4][Tags][tags][Tag][$containsi]={{tag1}}
&filters[$or][6][Tags][tags][Tag][$containsi]={{tag2}}
&filters[$or][8][Tags][tags][Tag][$containsi]={{tag3}}
&filters[$or][3][Tags][tags][Tag][$containsi]={{tag4}}
&filters[$or][5][Tags][tags][Tag][$containsi]={{tag5}}
&filters[$or][7][Tags][tags][Tag][$containsi]={{tag6}}
&filters[$and][0][title][$containsi]={{filter}}
or
...
&filters[$or][4][Tags][tags][Tag][$containsi]={{tag1}}
&filters[$or][6][Tags][tags][Tag][$containsi]={{tag2}}
&filters[$or][8][Tags][tags][Tag][$containsi]={{tag3}}
&filters[$or][3][Tags][tags][Tag][$containsi]={{tag4}}
&filters[$or][5][Tags][tags][Tag][$containsi]={{tag5}}
&filters[$or][7][Tags][tags][Tag][$containsi]={{tag6}}
&filters[title][$containsi]={{filter}}
Any help will be appreciated
I actually think I have found the answer. Could not find it anywhere in the documentation (https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#complex-filtering)
{{host}}/api/blog?sort=publishedAt%3Adesc
&populate=Tags.tags
&populate=Image
&pagination[page]=1
&pagination[pageSize]=25
&locale=en
&filters[$and][0][$or][0][title][$containsi]={{filter}}
&filters[$and][0][$or][1][introduction][$containsi]={{filter}}
&filters[$and][0][$or][2][body][$containsi]={{filter}}
&filters[$and][1][$or][0][Tags][tags][Tag][$containsi]={{tag1}}
&filters[$and][1][$or][1][Tags][tags][Tag][$containsi]={{tag2}}
&filters[$and][1][$or][2][Tags][tags][Tag][$containsi]={{tag3}}
&filters[$and][1][$or][3][Tags][tags][Tag][$containsi]={{tag4}}
&filters[$and][1][$or][4][Tags][tags][Tag][$containsi]={{tag5}}
&filters[$and][1][$or][5][Tags][tags][Tag][$containsi]={{tag6}}
Note the [NUMBER] sections grouping the ANDs and OR's ...
Once you know it, it looks logical :-)

DMQL2 Query Syntax for PHRets v2 Seach() to include filter arguments?

(It's been a while since I've been here.)
I've been using the first version of PHRets v1 for years, and understood it well enough to get by, but now I'm trying to understand the advantages of v2.6.2. I've got it all installed and the basics are working fine. My issues are pretty much with comprehending fine points of query syntax that goes into the rets=>Search() statement. (I'm much more familiar with SQL statements). Specifically, I'd like to have a query return a list of properties, EXCLUDING those which already have the status of "Sold".
Here's where I am stuck: If I start with this
`$results = $rets->Search('Property', 'A','*',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);`
That works well enough. BUT I'd like to fit in a filter like:
"LIST_15 != Sold", or "NOT LIST_15=Sold"...something like that. I don't get how to fit/type that into a PHRets Search().
I like PHRets but it is so hard to find well-organized/complete documentation about specific things like this. Thanks in advance.
As in my comment above I've figured out that the filter goes in the third argument position ('*', as in the original question). The tricky thing was having to find a specific "sold" code for each class of properties and placing it in that position like so: '(LIST_15=~B4ZIT1Y75TZ)', (notice the =~ combination of characters that means "does not equal" in this context). I've found the code strings for each of the property types (not clear WHY they would need to be unique for each type of property: "Sold" is Sold for any type, after all) but the correct code for a single-family residential property (type 'A' ...at least for the MLS in which I have to search is:
$results = $rets->Search('Property', 'A','(LIST_15=~B4ZIT1Y75TZ)',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);
(again, the code to go with LIST_15 will be different for the different types of properties.) I think there is a better answer that involves more naturalistic language, but this works and I guess I will have to be satisfied with it for now. I hope this is of some use to anyone else struggling with this stuff.

Primitive type as data structure for API Blueprint

I want to use primitive type for describe data structure. Like so:
# Data Structures
## Video Delete (enum[number])
+ `0` - Successful deletion.
+ `1` - Error occured.
And the output is.
{
"enum": [
1,
0
],
"$schema": "http://json-schema.org/draft-04/schema#"
}
So description is missing. I've tried to put description in different places. I did a lot of things (do not wanna talk about them). Also I've tried to add info to enum values like so:
+ `0` (number) - Successful deletion.
I do not know whether this problem deals with MSON syntax or Aglio generator.
The syntax above is supported by MSON as far as I can tell. The problem is that Aglio doesn't do anything with the description, and when I went to look into adding it I realized that it isn't really supported in JSON Schema. There seem to be two methods people use to get around that fact:
Add the enumerated value descriptions to the main description, the Olio theme 1.6.2 has support for this but the C++ parser seems to still have some bugs around this feature:
## Video Delete (enum[number]) - 0 for success, 1 for error
Use a weird oneOf syntax where you create sets of single enums with a description. I don't recommend this.
Unfortunately the first option requires work on your part and can't easily be done in Aglio. Does anyone else have a better description and some samples of MSON input -> JSON Schema output?

Lucene.net and relational data searching

I have the following situation:
I have a person with default fields like: Name, FirstName, Phone, Email, ...
A person has many languageskills, the languageskill entity has the following fields: Language, Speaking, Writing, Understanding, Mothertongue
A person has many workexperiences, with fields: Office, Description, Period, Location
How would I index something like this with Lucene.net?
The following searches could be possible:
- FirstName:"Arno" AND LanguageSkill:(Language:"Dutch" AND Speaking:[3 TO 5])
- FirstName:"Arno" AND WorkExperience:(Description:"Marketing")
- FirstName:"Arno" AND WorkExperience:(Description:"Marketing" OR Description:"Sales")
- FirstName:"Arno" AND WorkExperience:(Description:"Programmer") AND LanguageSkill:(Language:"English" AND Speaking:[3 TO 5] AND MotherTongue:"true")
Would something like this be possible in Lucene, I've tried flattening my relations already where a document could look like this:
Name:"Stallen"
FirstName:"Arno"
WorkExperience:"Office=Lidl Description=Sales Location=London"
WorkExperience:"Office=Abro Description=Programmer Location=London"
LanguageSkill:"Language=Dutch Speaking=3 Writing=1 Understanding=3"
LanguageSkill:"Language=Egnlish Speaking=5 Writing=4 Understanding=5 MotherTongue=true"
"if all you have is a hammer, everything looks like a nail"
Your requirements suit better to relational databases. I would go that way since I don't see anything related with free text search
However if you have to use Lucene.Net you should flatten your data a little bit more such as
Name:"Stallen"
FirstName:"Arno"
WorkExperienceDescription:Sales
WorkExperienceLocation:London
LanguageSkillLanguage:Dutch
LanguageSkillLanguage:English
Of course this would result in some info loss and you would not be able to make a search like
FirstName:"Arno" AND LanguageSkill:(Language:"Dutch" AND Speaking:[3 TO 5])
PS: You can use the same fieldname (ex., LanguageSkillLanguage) multiple times in a single document.
I ended up using the Java version of Lucene (3.6) which contains parent child documents. I used IKVM to generate the .net DLL out of it.

How to write multilingual applications in Clojure?

I'm trying to figure out how to create a Compojure-based web-site with multilingual support. Is there any solutions like i18n or something like that?
The easiest way is to replace all your localized strings with a function calls like:
(i18n lang "help")
And implement that function to read localized string from a .properties file determined by lang parameter.
For that you don't need any libraries. It's a simple function.
To avoid reading files all the time you could read them in memory during your applications start with a def into a map named loaded-property-files where, lang is the key and the value is a map of message keys and appropriate localized messages.
This can be done like this:
(defn load-property-files [langs]
(let [default (into {} (read-properties "locale.properties"))]
(apply merge
(for [lang langs]
(assoc {} lang
(merge default
(into {} (read-properties (str "locale_" lang ".properties")))))))))
(def loaded-property-files
(load-property-files ["en" "es" "de"]))
If file loading performance is not a problem, but you'd like to be able to change the files more easily during runtime, just change the def to a function.
The function read-properties (originally from old clojure.contrib) looks like this:
(defn read-properties
"Read properties from file-able."
([fileable]
(into {} (map #(vector (keyword (key %)) (val %))
(try
(with-open [f (java.io.FileInputStream. (new java.io.File fileable))]
(doto (new java.util.Properties)
(.load f)))
(catch java.io.FileNotFoundException e {})))))
([fileable defaults] (merge (read-properties fileable) defaults)))
The localization string from default file would be used whenever that key isn't found in the specified map, i.e. new string that has just been added, and no one translated it in Spanish yet, would be shown in language from default locale.properties
Then your i18n function looks like this:
(defn i18n [lang code]
((loaded-property-files lang) code))
There is a new i18n library: https://github.com/ptaoussanis/tower with this rationale:
Tower is an attempt to present a simple, idiomatic internationalization and localization story for Clojure. It wraps standard Java functionality where possible, but it isn't afraid to step away from Java conventions when there's a good reason to.
I created clji18n for this, but I had to switch to other project before completing it. It's "almost" usable, you can give it a try.
kotarak's j18n (note that there is another j18n library for Java but they are different ones) seems good.
https://bitbucket.org/kotarak/j18n

Resources