Skip to content

Commit 613b6b7

Browse files
authored
Update 4-AI_image_multimodal_location_GPT.R
Improved results from Bing Location Recognition, now bringing Business POI
1 parent 2ff35b0 commit 613b6b7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

4-AI_image_multimodal_location_GPT.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ result <- sapply(place_types, grepl, hashwords, fixed = TRUE)
531531

532532
# Print which words from the Google Places API were found in the hashtags based on the image
533533
found_words <- place_types[result]
534-
tourism_tags <- c("castle","monastery","bridge","palace","statue","bell_cote")
534+
tourism_tags <- c("castle","monastery","bridge","palace","statue","bell_cote","hotel","fountain")
535535
if (length(tourism_tags[sapply(tourism_tags, grepl, hashwords, fixed = TRUE)])>0) {
536-
found_words <- c(found_words, "tourist_attraction")
536+
found_words <- c(found_words, "tourist_attraction", "travel")
537537
}
538538

539539
url <- ""
@@ -627,13 +627,27 @@ if(exists("df_land") && all(c("latitude", "longitude") %in% names(df_land))){ #
627627
landmarks <- rbind(landmarks, df_land2, fill=TRUE)
628628
}
629629
}
630+
631+
# Also bringing business POI, to check GPS coordinates and try to find a suitable one
632+
businessPOI <- sapply(content$resourceSets[[1]]$resources[[1]]$businessesAtLocation, has_any_word, words = c(found_words, unlist(strsplit(hashwords, " "))))
633+
businessPOI <- content$resourceSets[[1]]$resources[[1]]$businessesAtLocation[businessPOI]
634+
businessPOI <- dplyr::bind_rows(lapply(businessPOI, as.data.frame.list))
635+
df_land3 <- businessPOI %>% select(businessInfo.entityName, businessAddress.latitude, businessAddress.longitude)
636+
colnames(df_land3) <- c("description", "latitude", "longitude")
637+
if(exists("df_land3") && all(c("latitude", "longitude") %in% names(df_land3))){ # Bing Location has found Business POI
638+
df_land3$source <- "Bing Location Recognition"
639+
landmarks <- rbind(landmarks, df_land3, fill=TRUE)
640+
}
641+
630642
}
631643

632-
if (length(landmarks$score)!=0){ # Google Vision has found landmarks
644+
if (length(landmarks$score)!=0){ # Google or Azure Vision have found landmarks
633645
landmarks <- landmarks %>% select(description, latitude, longitude, source, score)
634646
} else {
635647
if (length(landmarks$description)!=0){ # Google Places or Bing Location have found possible POI
636648
landmarks <- landmarks %>% select(description, latitude, longitude, source)
649+
# removing rows with NA on the description
650+
landmarks <- landmarks[complete.cases(landmarks[ , description]),]
637651
} else {
638652
landmarks$latitude <- ""
639653
landmarks$longitude <- ""

0 commit comments

Comments
 (0)