Skip to content

Commit

Permalink
Merge pull request #2 from argrecsys/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ansegura7 authored Feb 4, 2022
2 parents 242d265 + 4e3a53c commit e4f18eb
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 296 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Arguments-enhanced IR
![version](https://img.shields.io/badge/version-0.2.0-blue)
![last-update](https://img.shields.io/badge/last_update-2/3/2022-orange)
![version](https://img.shields.io/badge/version-0.3.0-blue)
![last-update](https://img.shields.io/badge/last_update-2/4/2022-orange)
![license](https://img.shields.io/badge/license-Apache_2.0-brightgreen)

Argument-enhanced information retrieval repository. A case study in the Decide Madrid database.

## Screenshots
![arg-ir-gui](https://raw.githubusercontent.com/argrecsys/arg-enhanced-ir/main/images/gui.gif)

## Dependencies
The implemented solutions depend on or make use of the following libraries and .jar files:
- JDK 16
Expand Down
6 changes: 3 additions & 3 deletions code/ArgumentIR/Resources/views/proposal-info.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<h3>$TITLE$</h3>
<p>Date: $DATE$</p>
<p>Num. Supports: $NUM_SUPPORTS$ | Num Comments: $NUM_COMMENTS$</p>
<h3><a href="$URL$" target="_blank">$TITLE$</a></h3>
<p>$DATE$ | Comments: $NUM_COMMENTS$ | Supports: $NUM_SUPPORTS$</p>
<p>Proposal code: <b>$CODE$</b></p>
<p>Summary: $SUMMARY$</p>
<hr>
</div>
185 changes: 3 additions & 182 deletions code/ArgumentIR/src/es/uam/irg/decidemadrid/db/DMDBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

import es.uam.irg.db.MySQLDBConnector;
import es.uam.irg.decidemadrid.entities.*;
import es.uam.irg.nlp.am.arguments.Argument;
import es.uam.irg.nlp.am.arguments.ArgumentLinker;
import es.uam.irg.utils.FunctionUtils;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class DMDBManager {

Expand Down Expand Up @@ -72,71 +66,6 @@ public Map<Integer, DMComment> selectComments() throws Exception {
return comments;
}

public Map<Integer, DMComment> selectComments(Integer[] proposalIds) throws Exception {
Map<Integer, DMComment> comments = new HashMap<>();

if (proposalIds.length > 0) {
String query = "SELECT id, parentId, proposalId, userId, date, time, text, numVotes, numPositiveVotes, numNegativeVotes "
+ " FROM proposal_comments "
+ " WHERE proposalId IN (" + FunctionUtils.arrayToString(proposalIds, ",") + ");";
ResultSet rs = this.db.executeSelect(query);

while (rs != null && rs.next()) {
int id = rs.getInt("id");
int parentId = rs.getInt("parentId");
int proposalId = rs.getInt("proposalId");
int userId = rs.getInt("userId");
String date = rs.getDate("date").toString();
String time = rs.getTime("time").toString();
String text = rs.getString("text");
int votes = rs.getInt("numVotes");
int votesUp = rs.getInt("numPositiveVotes");
int votesDown = rs.getInt("numNegativeVotes");

DMComment comment = new DMComment(id, parentId, proposalId, userId, date, time, text, votes, votesUp, votesDown);
comments.put(id, comment);
}
rs.close();
}

return comments;
}

public Map<Integer, DMComment> selectComments(List<ArgumentLinker> lexicon) throws Exception {
Map<Integer, DMComment> comments = new HashMap<>();

if (lexicon.size() > 0) {
String whereCond = "";
for (int i = 0; i < lexicon.size(); i++) {
whereCond += (i > 0 ? " OR " : "") + "(text LIKE '% " + lexicon.get(i).linker + " %' OR text LIKE '%," + lexicon.get(i).linker + " %' OR text LIKE '%..." + lexicon.get(i).linker + " %')";
}

String query = "SELECT id, parentId, proposalId, userId, date, time, text, numVotes, numPositiveVotes, numNegativeVotes "
+ " FROM proposal_comments "
+ " WHERE " + whereCond + ";";
ResultSet rs = this.db.executeSelect(query);

while (rs != null && rs.next()) {
int id = rs.getInt("id");
int parentId = rs.getInt("parentId");
int proposalId = rs.getInt("proposalId");
int userId = rs.getInt("userId");
String date = rs.getDate("date").toString();
String time = rs.getTime("time").toString();
String text = rs.getString("text");
int votes = rs.getInt("numVotes");
int votesUp = rs.getInt("numPositiveVotes");
int votesDown = rs.getInt("numNegativeVotes");

DMComment comment = new DMComment(id, parentId, proposalId, userId, date, time, text, votes, votesUp, votesDown);
comments.put(id, comment);
}
rs.close();
}

return comments;
}

public Map<Integer, DMProposal> selectProposals() throws Exception {
Map<Integer, DMProposal> proposals = new HashMap<>();

Expand All @@ -145,130 +74,22 @@ public Map<Integer, DMProposal> selectProposals() throws Exception {

while (rs != null && rs.next()) {
int id = rs.getInt("id");
String code = rs.getString("code");
String title = rs.getString("title");
int userId = rs.getInt("userId");
String date = rs.getString("date");
String summary = rs.getString("summary");
String text = rs.getString("text");
int numComments = rs.getInt("numComments");
int numSupports = rs.getInt("numSupports");
String url = rs.getString("url");

DMProposal proposal = new DMProposal(id, title, userId, date, summary, text, numComments, numSupports);
DMProposal proposal = new DMProposal(id, code, title, userId, date, summary, text, numComments, numSupports, url);
proposals.put(id, proposal);
}
rs.close();

return proposals;
}

public Map<Integer, DMProposal> selectProposals(Integer[] proposalIds) throws Exception {
Map<Integer, DMProposal> proposals = new HashMap<>();

if (proposalIds.length > 0) {
String query = "SELECT id, title, userId, date, summary, text, numComments, numSupports "
+ " FROM proposals "
+ " WHERE id IN (" + FunctionUtils.arrayToString(proposalIds, ",") + ");";
ResultSet rs = this.db.executeSelect(query);

while (rs != null && rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
int userId = rs.getInt("userId");
String date = rs.getString("date");
String summary = rs.getString("summary");
String text = rs.getString("text");
int numComments = rs.getInt("numComments");
int numSupports = rs.getInt("numSupports");

DMProposal proposal = new DMProposal(id, title, userId, date, summary, text, numComments, numSupports);
proposals.put(id, proposal);
}
rs.close();
}

return proposals;
}

public Map<Integer, DMProposal> selectProposals(List<ArgumentLinker> lexicon) throws Exception {
Map<Integer, DMProposal> proposals = new HashMap<>();

if (lexicon.size() > 0) {
String whereCond = "";
for (int i = 0; i < lexicon.size(); i++) {
whereCond += (i > 0 ? " OR " : "") + "(summary LIKE '% " + lexicon.get(i).linker + " %' OR summary LIKE '%," + lexicon.get(i).linker + " %' OR summary LIKE '%..." + lexicon.get(i).linker + " %')";
}

String query = "SELECT id, title, userId, date, summary, text, numComments, numSupports "
+ " FROM proposals "
+ " WHERE " + whereCond + ";";
ResultSet rs = this.db.executeSelect(query);

while (rs != null && rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
int userId = rs.getInt("userId");
String date = rs.getString("date");
String summary = rs.getString("summary");
String text = rs.getString("text");
int numComments = rs.getInt("numComments");
int numSupports = rs.getInt("numSupports");

DMProposal proposal = new DMProposal(id, title, userId, date, summary, text, numComments, numSupports);
proposals.put(id, proposal);
}
rs.close();
}

return proposals;
}

public Map<Integer, DMProposalSummary> selectProposalsSummary(List<Argument> arguments) throws Exception {
Map<Integer, DMProposalSummary> proposals = new HashMap<>();

if (arguments.size() > 0) {
Set<Integer> setIds = new HashSet();
int proposalID;
String whereCond = "";

for (Argument argument : arguments) {
proposalID = argument.getProposalId();

if (!setIds.contains(proposalID)) {
setIds.add(proposalID);
whereCond += (whereCond.equals("") ? "" : ", ") + proposalID;
}
}

String query = "SELECT p.id, p.date, p.title, "
+ " IFNULL(GROUP_CONCAT(DISTINCT pc.category), '') AS categories, "
+ " IFNULL(GROUP_CONCAT(DISTINCT pd.district), '') AS districts, "
+ " IFNULL(GROUP_CONCAT(DISTINCT pt.topic), '') AS topic "
+ " FROM proposals AS p "
+ " LEFT OUTER JOIN "
+ " proposal_categories AS pc ON p.id = pc.id "
+ " LEFT OUTER JOIN "
+ " proposal_locations AS pd ON p.id = pd.id "
+ " LEFT OUTER JOIN "
+ " proposal_topics AS pt ON p.id = pt.id "
+ " WHERE p.id IN (" + whereCond + ")"
+ " GROUP BY p.id, p.date, p.title;";
ResultSet rs = this.db.executeSelect(query);

while (rs != null && rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
String date = rs.getString("date");
String categories = rs.getString("categories").toLowerCase();
String districts = rs.getString("districts").toLowerCase();
String topics = rs.getString("topic").toLowerCase();

DMProposalSummary proposal = new DMProposalSummary(id, title, date, categories, districts, topics);
proposals.put(id, proposal);
}
rs.close();
}

return proposals;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

public class DMProposal {

private int id;
private String title;
private int userId;
public final static String HOME_PAGE = "https://decide.madrid.es";

private String code;
private String date;
private int day;
private int id;
private int month;
private int year;
private String summary;
private String text;
private int numComments;
private int numSupports;
private String summary;
private String text;
private String title;
private String url;
private int userId;
private int year;

public DMProposal(int id, String title, int userId, String date, String summary, String text, int numComments, int numSupports) {
public DMProposal(int id, String code, String title, int userId, String date, String summary, String text, int numComments, int numSupports, String url) {
this.id = id;
this.code = code;
this.title = title;
this.userId = userId;
this.date = date;
Expand All @@ -27,18 +32,29 @@ public DMProposal(int id, String title, int userId, String date, String summary,
this.text = text;
this.numComments = numComments;
this.numSupports = numSupports;
this.url = HOME_PAGE + url;
}

public int getId() {
return id;
}

public String getTitle() {
return title;
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final DMProposal other = (DMProposal) obj;
if (this.id != other.id) {
return false;
}
return true;
}

public int getUserId() {
return userId;
public String getCode() {
return code;
}

public String getDate() {
Expand All @@ -49,12 +65,20 @@ public int getDay() {
return day;
}

public int getId() {
return id;
}

public int getMonth() {
return month;
}

public int getYear() {
return year;
public int getNumComments() {
return numComments;
}

public int getNumSupports() {
return numSupports;
}

public String getSummary() {
Expand All @@ -65,12 +89,20 @@ public String getText() {
return text;
}

public int getNumComments() {
return numComments;
public String getTitle() {
return title;
}

public int getNumSupports() {
return numSupports;
public String getUrl() {
return url;
}

public int getUserId() {
return userId;
}

public int getYear() {
return year;
}

@Override
Expand All @@ -80,24 +112,6 @@ public int hashCode() {
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final DMProposal other = (DMProposal) obj;
if (this.id != other.id) {
return false;
}
return true;
}

@Override
public String toString() {
return "DMProposal{" + "id=" + id + ", title=" + title + ", userId=" + userId + ", date=" + date + ", summary=" + summary + ", text=" + text + ", numComments=" + numComments + ", numSupports=" + numSupports + '}';
Expand Down
Loading

0 comments on commit e4f18eb

Please sign in to comment.