Add P3999 (date of closure) support for non-existent places

This commit is contained in:
sonalyadav 2025-04-10 22:23:12 +05:30
parent ec8e39d069
commit 845890133a
4 changed files with 13 additions and 44 deletions

View file

@ -12,7 +12,6 @@ import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.model.NearbyResultItem;
import fr.free.nrw.commons.utils.LocationUtils;
import fr.free.nrw.commons.utils.PlaceUtils;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import timber.log.Timber;
@ -40,7 +39,6 @@ public class Place implements Parcelable {
public Sitelinks siteLinks;
private boolean isMonument;
private String thumb;
private String dateOfClosure;
public Place() {
language = null;
@ -53,12 +51,6 @@ public class Place implements Parcelable {
exists = null;
siteLinks = null;
entityID = null;
dateOfClosure = null;
}
public Place(String language, String name, Label label, String longDescription, LatLng location,
String category, Sitelinks siteLinks, String pic, Boolean exists, String entityID, String dateOfClosure) {
this(language, name, label, longDescription, location, category, siteLinks, pic, exists, entityID);
this.dateOfClosure = dateOfClosure;
}
public Place(String language, String name, Label label, String longDescription, LatLng location,
@ -117,7 +109,6 @@ public class Place implements Parcelable {
this.exists = Boolean.parseBoolean(existString);
this.isMonument = in.readInt() == 1;
this.entityID = in.readString();
this.dateOfClosure = in.readString(); // Added for P3999
}
public static Place from(NearbyResultItem item) {
@ -148,7 +139,6 @@ public class Place implements Parcelable {
+ ((description != null && !description.isEmpty())
? " (" + description + ")" : "")
: description);
item.getDateOfClosure();
return new Place(
item.getLabel().getLanguage(),
item.getLabel().getValue(),
@ -163,27 +153,11 @@ public class Place implements Parcelable {
.build(),
item.getPic().getValue(),
// Checking if the place exists or not
(item.getDestroyed().getValue() == "" && item.getEndTime().getValue() == ""),
entityId,
(item.getDateOfClosure() != null && !item.getDateOfClosure().getValue().isEmpty())
? item.getDateOfClosure().getValue()
: null);
}
// Added new method to check if place is closed
public boolean isClosed() {
return (dateOfClosure != null && !dateOfClosure.isEmpty()) || !exists;
(item.getDestroyed().getValue() == "") && (item.getEndTime().getValue() == "")
&& (item.getdateOfOfficialClosure().getValue() == ""),
entityId);
}
public String getDisplayName() {
return (isClosed() ? "" : "") + name;
}
public String getDateOfClosure() {
return dateOfClosure;
}
public void setDateOfClosure(String dateOfClosure) {
this.dateOfClosure = dateOfClosure;
}
/**
* Gets the language of the caption ie name.
*
@ -334,17 +308,15 @@ public class Place implements Parcelable {
public boolean equals(Object o) {
if (o instanceof Place) {
Place that = (Place) o;
return this.name.equals(that.name) && this.location.equals(that.location) &&
(Objects.equals(this.dateOfClosure, that.dateOfClosure));
return this.name.equals(that.name) && this.location.equals(that.location);
} else {
return false;
}
return false;
}
@Override
public int hashCode() {
int result = this.name.hashCode() * 31 + this.location.hashCode();
result = 31 * result + (dateOfClosure != null ? dateOfClosure.hashCode() : 0); // Add this line
return result;
return this.name.hashCode() * 31 + this.location.hashCode();
}
@Override
@ -361,7 +333,6 @@ public class Place implements Parcelable {
", pic='" + pic + '\'' +
", exists='" + exists.toString() + '\'' +
", entityID='" + entityID + '\'' +
", dateOfClosure='" + dateOfClosure + '\'' +
'}';
}
@ -383,7 +354,6 @@ public class Place implements Parcelable {
dest.writeString(entityID);
dest.writeString(exists.toString());
dest.writeInt(isMonument ? 1 : 0);
dest.writeString(dateOfClosure);
}
public static final Creator<Place> CREATOR = new Creator<Place>() {

View file

@ -78,7 +78,7 @@ fun placeAdapterDelegate(
nearbyButtonLayout.iconOverflow.setOnLongClickListener { onOverFlowLongPressed() }
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
bind {
tvName.text = item.getDisplayName()
tvName.text = item.name
val descriptionText: String = item.longDescription
if (descriptionText == "?") {
tvDesc.setText(R.string.no_description_found)

View file

@ -18,7 +18,7 @@ class NearbyResultItem(
@field:SerializedName("description") private val description: ResultTuple?,
@field:SerializedName("endTime") private val endTime: ResultTuple?,
@field:SerializedName("monument") private val monument: ResultTuple?,
@field:SerializedName("dateOfClosure") private val dateOfClosure: ResultTuple? = null
@field:SerializedName("dateOfOfficialClosure") private val dateOfOfficialClosure: ResultTuple?,
) {
fun getItem(): ResultTuple = item ?: ResultTuple()
@ -42,6 +42,8 @@ class NearbyResultItem(
fun getDestroyed(): ResultTuple = destroyed ?: ResultTuple()
fun getdateOfOfficialClosure(): ResultTuple = dateOfOfficialClosure ?: ResultTuple()
fun getDescription(): ResultTuple = description ?: ResultTuple()
fun getEndTime(): ResultTuple = endTime ?: ResultTuple()
@ -50,5 +52,4 @@ class NearbyResultItem(
fun getMonument(): ResultTuple? = monument
fun getDateOfClosure(): ResultTuple = dateOfClosure ?: ResultTuple()
}

View file

@ -10,7 +10,7 @@ SELECT
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
(SAMPLE(?commonsArticle) AS ?commonsArticle)
(SAMPLE(?commonsCategory) AS ?commonsCategory)
(SAMPLE(?dateOfClosure) AS ?dateOfClosure)
(SAMPLE(?dateOfOfficialClosure) AS ?dateOfOfficialClosure)
WHERE {
SERVICE <https://query.wikidata.org/sparql> {
values ?item {
@ -46,6 +46,7 @@ WHERE {
# Get existence
OPTIONAL {?item wdt:P576 ?destroyed}
OPTIONAL {?item wdt:P582 ?endTime}
OPTIONAL {?item wdt:P3999 ?dateOfOfficialClosure}
# Get Commons category
OPTIONAL {?item wdt:P373 ?commonsCategory}
@ -61,8 +62,5 @@ WHERE {
?commonsArticle schema:about ?item.
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
}
# Get date of official closure (P3999)
OPTIONAL {?item wdt:P3999 ?dateOfClosure}
}
GROUP BY ?item