Obtaining next set of results - here-api

I've searched around but cannot seem to find the answer to this, I need to access more pages worth of results from a places search. I noticed in the JSON response there is a next field with a URL that, when clicked in the browser, calls a further 20 results. However I haven't been able to access this field in my C# application. Below is the JSON response (text format).
{
results: {next:https://places.cit.api.here.com/places/v1/discover/search;context=Zmxv...
items: [
{ The Botanist }
{ Alexanders Jazz Theatre Bar }
{ The Architect }
{ 1539 Restaurant & Bar }
{ Barlounge Chester }
{ Meze }
{ Hanky Panky Pancakes }
{ The Slowboat }
{ The Moorings }
{ Missoula }
{ Istanbul BBQ }
{ Chip-O-Dee }
{ The Flower Cup }
{ Mama K's Burritos }
{ The Stage Door Cafe Chester }
{ Cinderbox Coffee }
{ Wok&Go }
{ Covino }
{ Urbano 32 }
{ Beatons Tearooms }
]
}
search: {
context: { urn:nlp-types:place }
supportsPanning:true
ranking:category-recommendations
}
}
And my C# classes used to access the fields, the next string just returns null:
[System.Serializable]
public class Response
{
public results results;
}
[System.Serializable]
public class results
{
public string next;
public string previous;
public items[] items;
}
Thank you

Places API is built from a consumer perspective and restricted only to return the first 100(relevant) POIs around a location. There is no provision to get all the POIs as of today.

Related

Is there any method to save the ContractionHierarchy in files using jgrapht

I have used jgrapht to analyse some graph problems. Now I am working with big graph (with more than ten millions nodes ) and use CH algorithm.
What troubles me is the precomputation of CH is so long, nearly 2 hours. And I found the
preprocessed data is saved in ContractionHierarchy as below.
public static class ContractionHierarchy<V, E> {
private Graph<V, E> graph;
private Graph<ContractionVertex<V>, ContractionEdge<E>> contractionGraph;
private Map<V, ContractionVertex<V>> contractionMapping;
public Graph<V, E> getGraph() {
return this.graph;
}
public Graph<ContractionVertex<V>, ContractionEdge<E>> getContractionGraph() {
return this.contractionGraph;
}
public Map<V, ContractionVertex<V>> getContractionMapping() {
return this.contractionMapping;
}
ContractionHierarchy(Graph<V, E> graph, Graph<ContractionVertex<V>, ContractionEdge<E>> contractionGraph, Map<V, ContractionVertex<V>> contractionMapping) {
this.graph = graph;
this.contractionGraph = contractionGraph;
this.contractionMapping = contractionMapping;
}
public void unpackBackward(ContractionEdge<E> edge, LinkedList<V> vertexList, LinkedList<E> edgeList) {
if (edge.bypassedEdges == null) {
vertexList.addFirst(((ContractionVertex)this.contractionGraph.getEdgeSource(edge)).vertex);
edgeList.addFirst(edge.edge);
} else {
this.unpackBackward((ContractionEdge)edge.bypassedEdges.getSecond(), vertexList, edgeList);
this.unpackBackward((ContractionEdge)edge.bypassedEdges.getFirst(), vertexList, edgeList);
}
}
public void unpackForward(ContractionEdge<E> edge, LinkedList<V> vertexList, LinkedList<E> edgeList) {
if (edge.bypassedEdges == null) {
vertexList.addLast(((ContractionVertex)this.contractionGraph.getEdgeTarget(edge)).vertex);
edgeList.addLast(edge.edge);
} else {
this.unpackForward((ContractionEdge)edge.bypassedEdges.getFirst(), vertexList, edgeList);
this.unpackForward((ContractionEdge)edge.bypassedEdges.getSecond(), vertexList, edgeList);
}
}
}
So I wonder is there any way to export ContractionHierarchy to files so that I can use it next time without compile the precomputation and query directly.

TornadoFX:proper way to bind model

I was taking a look at this :
tornadofx
and tried to expand on it with database connection and little more options, (not all of them make sense, but its just playing in a sandbox).
Even though table can be directly edited and the data will persist in database, i did try to do edit through text fields too. actual table editing would happen through different view and not table itself, as i said its just example.
Database used is Jetbrains Exposed.
object Categories : IntIdTable() {
val name = varchar("name", 64).uniqueIndex()
val description = varchar("description", 128)
}
class Category(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Category>(Categories)
var name by Categories.name
var description by Categories.description
override fun toString(): String {
return "Category(name=\"$name\", description=\"$description\")"
}
}
now controller looks something like this, functions are just rudimentary and picked as an example.
typealias ModelToDirtyState = Map.Entry<CategoryModel, TableColumnDirtyState<CategoryModel>>
class CategoryModel() : ItemViewModel<Category>() {
val name: SimpleStringProperty = bind(Category::name)
val description: SimpleStringProperty = bind(Category::description)
}
class DBController : Controller() {
val categories: ObservableList<CategoryModel> by lazy {
transaction {
SchemaUtils.create(Categories)
Category.all().map {
CategoryModel().apply {
item = it
}
}.observable()
}
}
init {
Database.connect(
"jdbc:mysql://localhost:3306/test", driver = "com.mysql.cj.jdbc.Driver",
user = "test", password = "test"
)
TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
}
fun deleteCategory(model: CategoryModel) {
runAsync {
transaction {
model.item.delete()
}
}
categories.remove(model)
}
fun updateCategory(model: CategoryModel) {
transaction {
Categories.update {
model.commit()
}
}
}
fun commitDirty(modelDirtyMappings: Sequence<ModelToDirtyState>) {
transaction {
modelDirtyMappings.filter { it.value.isDirty }.forEach {
it.key.commit()
println(it.key)// commit value to database
it.value.commit() // clear dirty state
}
}
}
Just to quickly comment on controller, delete method works as "intended" however the update one does not, it does not work in sense that after using delete item is remove both from database and tableview(underlying list) itself, and when i do update its not, now i know the reason, i call remove manually on both database and list, now for update perhaps i could do change listener, or maybe tornadofx can do this for me, i just cant set it up to do it. Following code will make things clearer i think.
class CategoryEditor : View("Categories") {
val categoryModel: CategoryModel by inject()
val dbController: DBController by inject()
var categoryTable: TableViewEditModel<CategoryModel> by singleAssign()
var categories: ObservableList<CategoryModel> by singleAssign()
override val root = borderpane {
categories = dbController.categories
center = vbox {
buttonbar {
button("Commit") {
action {
dbController.commitDirty(categoryTable.items.asSequence())
}
}
button("Roll;back") {
action {
categoryTable.rollback()
}
}
// This model only works when i use categorytable.tableview.selected item, if i use categoryModel, list gets updated but not the view itself
// Question #1 how to use just categoryModel variable without need to use categorytable.tableview.selecteditem
button("Delete ") {
action {
val model = categoryTable.tableView.selectedItem
when (model) {
null -> return#action
else -> dbController.deleteCategory(model)
}
}
}
//And here no matter what i did i could not make the view update
button("Update") {
action {
when (categoryModel) {
null -> return#action
else -> dbController.updateCategory(categoryModel)
}
categoryTable.tableView.refresh()
}
}
}
tableview<CategoryModel> {
categoryTable = editModel
items = categories
enableCellEditing()
enableDirtyTracking()
onUserSelect() {
//open a dialog
}
//DOES WORK
categoryModel.rebindOnChange(this) { selectedItem ->
item = selectedItem?.item ?: CategoryModel().item
}
// Question #2. why bindSelected does not work, and i have to do it like above
//DOES NOT WORK
// bindSelected(categoryModel)
//
column("Name", CategoryModel::name).makeEditable()
column("Description", CategoryModel::description).makeEditable()
}
}
right = form {
fieldset {
field("Name") {
textfield(categoryModel.name)
}
}
fieldset {
field("Description") {
textfield(categoryModel.description)
}
}
button("ADD CATEGORY") {
action {
dbController.addCategory(categoryModel.name.value, categoryModel.description.value)
}
}
}
}
}
I apologize for huge amount of code, also in last code snipped i left questions in form of comments where i fail to achive desired results.
I am sure i am not properly binding code, i just dont see why, also i sometimes use one variable to update data, my declared one "categoryModel" and sometimes i use tableview.selecteditem, it just seems hacky and i cant seem to grasp way.
Thank you!

sass-lint restrict partial BEM rule

Let's say I have a class: myclass__button-create--success.
I want to limit the usage of -create part in:
.myclass__button {
&-create {
}
}
As it's not a new block, element or modifier.
Allowed structures:
.myclass__button-create {
&--success {
}
}
.myclass {
&__button-create {
}
}
.myclass__button-create--success {
}
Any idea how to achieve this restriction using sass-lint?

Realm.firstFirstAsync().asObservable() isn't consistently working with RxJava.switchIfEmpty

I am trying to create function which reads a object from realm and emit an empty observable if the object isn't found. The code below works to some degree because I can stop it with the debugger and see it hit the Observable.empty():
fun readFromRealm(id: String): Observable<Player> {
return realm.where(Player::class.java)
.equalTo("id", id)
.findFirstAsync()
.asObservable<Player>()
.filter { it.isLoaded }
.flatMap {
if (it.isValid)
Observable.just(it)
else
Observable.empty()
}
}
But when I try to use a switchIfEmpty on the Observable the code never emits defaultPlayer when it is not found in realm.
return readFromRealm(playerId)
.take(1)
.map{ // do something with emitted observable }
.switchIfEmpty(Observable.just(defaultPlayer)) // use this if no player found
The strange thing is that if I update the original method to include a first() prior to the flatMap :
fun readFromRealm(id: String): Observable<Player> {
return realm.where(Player::class.java)
.equalTo("id", id)
.findFirstAsync()
.asObservable<Player>()
.filter { it.isLoaded }
.first() // add first
.flatMap {
if (it.isValid)
Observable.just(it)
else
Observable.empty()
}
}
Everything starts working as expected, but I believe this version will kill auto updating because it will only capture the first result emitted after the filter.
I'm still trying to grok Realm and Rx so I'm probably doing something dumb.
EDIT: I have created a sample project which highlights the issue I'm seeing - https://github.com/donaldlittlepie/realm-async-issue
For reasons I don't totally understand. If you move take(1) just above the
flatMap and below the filter it should work correctly:
realm.where(Dog.class)
.equalTo("id", 0L)
.findFirstAsync()
.asObservable()
.cast(Dog.class)
.filter(new Func1<RealmObject, Boolean>() {
#Override
public Boolean call(RealmObject realmObject) {
return realmObject.isLoaded();
}
})
.take(1) // <== here
.flatMap(new Func1<Dog, Observable<Dog>>() {
#Override
public Observable<Dog> call(Dog realmObject) {
if (realmObject.isValid()) {
return Observable.just(realmObject);
} else {
return Observable.empty();
}
}
})
.map(new Func1<Dog, Dog>() {
#Override
public Dog call(Dog dog) {
dog.setName("mapped " + dog.getName());
return dog;
}
})
.switchIfEmpty(Observable.just(createDefaultDog()))
.subscribe(new Action1<Dog>() {
#Override
public void call(Dog dog) {
textView.setText(dog.getName());
}
}, new Action1<Throwable>() {
#Override
public void call(Throwable throwable) {
textView.setText(throwable.toString());
}
});
My best guess is that before, flatMap was called repeatedly, returning Observable.empty() multiple times. Perhaps that effects the Observable chain in some unexpected way.

Paginate generate number

I want to add page number in my application, like 1 2 3 4. My paginated class code is:
public bool HasPreviousPage
{
get
{
return (PageIndex > 0);
}
}
public bool HasNextPage
{
get
{
return (PageIndex+1<TotalPages);
}
}
This code generates link and goto next page, but can't display page number.
Add this property:
public IEnumerable<int> Pages
{
get
{
for(var page=1; page <= TotalPages; pages++)
yield return page;
}
}
You could use it for rendering the pages in your page (i.e. using a repeater).
Hope it helps.

Resources