|
| 1 | +package attributes; |
| 2 | + |
| 3 | +import attributes.abstrakt.Abstract; |
| 4 | +import attributes.affiliations.Affiliations; |
| 5 | +import attributes.authors.Authors; |
| 6 | +import attributes.contact.ContactInfo; |
| 7 | +import attributes.date.PublicationDate; |
| 8 | +import attributes.doi.DOI; |
| 9 | +import attributes.language.Language; |
| 10 | +import attributes.title.Title; |
| 11 | +import attributes.url.Url; |
| 12 | +import org.json.JSONObject; |
| 13 | +import org.json.XML; |
| 14 | + |
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.Calendar; |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +public class Attributes implements Runnable { |
| 20 | + private final String title; |
| 21 | + private final String name; |
| 22 | + private final String abstrakt; |
| 23 | + private final String summary=""; |
| 24 | + private final List<String> authors; |
| 25 | + private final List<String> affiliations; |
| 26 | + private final List<String> contact; |
| 27 | + private final String doi; |
| 28 | + private final String date; |
| 29 | + private final String status; |
| 30 | + private final List<String> URLs; |
| 31 | + private final List<String> tags=new ArrayList<>(); |
| 32 | + private List<String> funding; |
| 33 | + private String language; |
| 34 | + private CodeStats cs; |
| 35 | + |
| 36 | + private final JSONObject xmlJSONObj; |
| 37 | + private final String m_nlm; |
| 38 | +// private List<FundingInfo> funding_list; |
| 39 | + |
| 40 | + private JSONObject final_object; |
| 41 | + |
| 42 | + // ------------------------------------------------------------- // |
| 43 | + |
| 44 | + public Attributes(String nlm, String filename, boolean fromPMC) throws Exception { |
| 45 | + m_nlm = nlm; |
| 46 | + xmlJSONObj = XML.toJSONObject(nlm); |
| 47 | + funding = null; |
| 48 | + language = null; |
| 49 | + cs = null; |
| 50 | + |
| 51 | + run(); |
| 52 | + |
| 53 | + Calendar title_start = Calendar.getInstance(); |
| 54 | + Title t = new Title(xmlJSONObj); |
| 55 | + title = t.getTitle(); |
| 56 | + Calendar title_end = Calendar.getInstance(); |
| 57 | + |
| 58 | + Calendar author_start = Calendar.getInstance(); |
| 59 | + Authors au = new Authors(xmlJSONObj,fromPMC); |
| 60 | + authors = au.getAuthors(); |
| 61 | + for (int i = 0; i < authors.size(); i++) { |
| 62 | + authors.set(i, authors.get(i).trim()); |
| 63 | + } |
| 64 | + Calendar author_end = Calendar.getInstance(); |
| 65 | + Calendar aff_start = Calendar.getInstance(); |
| 66 | + Affiliations aff = new Affiliations(xmlJSONObj,fromPMC); |
| 67 | + affiliations = aff.getAffiliations(); |
| 68 | + for (int i = 0; i < affiliations.size(); i++) { |
| 69 | + affiliations.set(i, affiliations.get(i).trim()); |
| 70 | + } |
| 71 | + Calendar aff_end = Calendar.getInstance(); |
| 72 | + Calendar contact_start = Calendar.getInstance(); |
| 73 | + ContactInfo con = new ContactInfo(nlm, fromPMC); |
| 74 | + contact = con.getContact(); |
| 75 | + for (int i = 0; i < contact.size(); i++) { |
| 76 | + contact.set(i, contact.get(i).trim()); |
| 77 | + } |
| 78 | + Calendar contact_end = Calendar.getInstance(); |
| 79 | + Calendar doi_start = Calendar.getInstance(); |
| 80 | + DOI d2 = new DOI(xmlJSONObj, fromPMC); |
| 81 | + doi = d2.getDoi(); |
| 82 | + Calendar doi_end = Calendar.getInstance(); |
| 83 | + Calendar date_start = Calendar.getInstance(); |
| 84 | + PublicationDate d = new PublicationDate(xmlJSONObj, fromPMC); |
| 85 | + date = d.getDate(); |
| 86 | + Calendar date_end = Calendar.getInstance(); |
| 87 | + |
| 88 | + |
| 89 | + Calendar url_start = Calendar.getInstance(); |
| 90 | + Url url_link = new Url(xmlJSONObj, filename); |
| 91 | + URLs = url_link.getUrl(); |
| 92 | + for (int i = 0; i < URLs.size(); i++) { |
| 93 | + URLs.set(i, URLs.get(i).trim()); |
| 94 | + } |
| 95 | + |
| 96 | + if(URLs.isEmpty()){ |
| 97 | + status = "URL links are no longer valid"; |
| 98 | + }else{ |
| 99 | + status = "Success"; |
| 100 | + } |
| 101 | + Calendar url_end = Calendar.getInstance(); |
| 102 | + |
| 103 | + |
| 104 | + Calendar abstract_start = Calendar.getInstance(); |
| 105 | + Abstract a = new Abstract(nlm,fromPMC); |
| 106 | + abstrakt = a.getAbstract().trim(); |
| 107 | + Calendar abstract_end = Calendar.getInstance(); |
| 108 | + |
| 109 | + Calendar name_start = Calendar.getInstance(); |
| 110 | + ToolName tool_name = new ToolName(title, URLs); |
| 111 | + |
| 112 | + if(tool_name.getName()==null){ |
| 113 | + name = ""; |
| 114 | + }else{ |
| 115 | + name = tool_name.getName(); |
| 116 | + } |
| 117 | + Calendar name_end = Calendar.getInstance(); |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + Calendar lang_start = Calendar.getInstance(); |
| 122 | + String code_url = ""; |
| 123 | + for(String url: URLs){ |
| 124 | + if(url.contains("github")){ |
| 125 | + code_url = url; |
| 126 | + cs = new CodeStats(code_url, name); |
| 127 | + if(cs.hasStats()){ |
| 128 | + break; |
| 129 | + } |
| 130 | + } |
| 131 | + if(url.contains("sourceforge") || url.contains("bitbucket")){ |
| 132 | + code_url = url; |
| 133 | + } |
| 134 | + } |
| 135 | + if(cs==null){ |
| 136 | + cs = new CodeStats(code_url, name); |
| 137 | + } |
| 138 | + |
| 139 | + |
| 140 | + final_object = new JSONObject(); |
| 141 | + final_object.put("publicationTitle", title); |
| 142 | + final_object.put("publicationAbstract", abstrakt); |
| 143 | + final_object.put("title", title); |
| 144 | + final_object.put("authors", authors.toArray()); |
| 145 | + final_object.put("institutions", affiliations.toArray()); |
| 146 | + final_object.put("contactInfo", contact.toArray()); |
| 147 | + final_object.put("publicationDOI", doi); |
| 148 | + final_object.put("publicationDate", date); |
| 149 | + final_object.put("URLs", URLs.toArray()); |
| 150 | + final_object.put("status", status); |
| 151 | + final_object.put("toolName", name); |
| 152 | + final_object.put("fulltext", this.m_nlm.replaceAll("<.*?>", " ")); |
| 153 | + |
| 154 | + if(cs.hasStats()) { |
| 155 | + final_object.put("programmingLanguage", cs.getLanguage()); |
| 156 | + final_object.put("forks", cs.getForks()); |
| 157 | + final_object.put("shortDescription", cs.getDescription()); |
| 158 | + final_object.put("license", cs.getLicense()); |
| 159 | + final_object.put("sourceCodeLink", cs.getRepo_link()); |
| 160 | + final_object.put("dateCreated", cs.getDate_created()); |
| 161 | + final_object.put("dateUpdated", cs.getDate_updated()); |
| 162 | + final_object.put("downloads", cs.getDownloads()); |
| 163 | + final_object.put("codeSize", cs.getSize()); |
| 164 | + final_object.put("sourceCodeLink", cs.getRepo_link()); |
| 165 | + final_object.put("numIssues", cs.getIssues()); |
| 166 | + final_object.put("subscribers", cs.getSubscribers()); |
| 167 | + if(!cs.getHomepage().isEmpty()) { |
| 168 | + final_object.put("homepage", cs.getHomepage()); |
| 169 | + } |
| 170 | + if(cs.getRepo_name()!=null && !cs.getRepo_name().isEmpty()){ |
| 171 | + final_object.put("toolName", cs.getRepo_name()); |
| 172 | + } |
| 173 | + |
| 174 | + Calendar lang_end = Calendar.getInstance(); |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + // ------------------------------------------------------------ // |
| 179 | + |
| 180 | + public void run() { |
| 181 | + try { |
| 182 | + Calendar funding_start = Calendar.getInstance(); |
| 183 | +// Funding f = new Funding(m_nlm, 0); |
| 184 | +// funding_list = f.getFunding(); |
| 185 | + Calendar funding_end = Calendar.getInstance(); |
| 186 | +// System.out.println("Time funding: "); |
| 187 | +// System.out.println(funding_end.getTimeInMillis() - funding_start.getTimeInMillis()); |
| 188 | + } catch (Exception e) { |
| 189 | + e.printStackTrace(); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + public void setID(int id){ |
| 194 | + final_object.put("id", id); |
| 195 | + } |
| 196 | + |
| 197 | + public String getTitle(){ |
| 198 | + return title; |
| 199 | + } |
| 200 | + |
| 201 | + public String getName() { |
| 202 | + return name; |
| 203 | + } |
| 204 | + |
| 205 | + public String getSummary() { |
| 206 | + return summary; |
| 207 | + } |
| 208 | + |
| 209 | + public List<String> getAuthor(){ |
| 210 | + return authors; |
| 211 | + } |
| 212 | + |
| 213 | + public List<String> getAffiliation(){ |
| 214 | + return affiliations; |
| 215 | + } |
| 216 | + |
| 217 | + public String getAbstrakt(){ |
| 218 | + return abstrakt; |
| 219 | + } |
| 220 | + |
| 221 | + public List<String> getContact(){ |
| 222 | + return contact; |
| 223 | + } |
| 224 | + |
| 225 | + public String getDOI(){ |
| 226 | + return doi; |
| 227 | + } |
| 228 | + |
| 229 | + public String getDate() { |
| 230 | + return date; |
| 231 | + } |
| 232 | + |
| 233 | + public String getStatus() { |
| 234 | + return status; |
| 235 | + } |
| 236 | + |
| 237 | + public List<String> getURL(){ |
| 238 | + return URLs; |
| 239 | + } |
| 240 | + |
| 241 | +// private List<FundingInfo> getFundingList() { |
| 242 | +// return funding_list; |
| 243 | +// } |
| 244 | + |
| 245 | + public List<String> getFundingStr() { |
| 246 | +// List<String> fa = new ArrayList<>(); |
| 247 | +// for (FundingInfo fi : getFundingList()) { |
| 248 | +// fa.add(fi.toString()); |
| 249 | +// } |
| 250 | +// funding = fa; |
| 251 | + return this.funding; |
| 252 | + } |
| 253 | + |
| 254 | + public String getLanguage(){ |
| 255 | + return language; |
| 256 | + } |
| 257 | + |
| 258 | + public List<String> getTags(){ |
| 259 | + return tags; |
| 260 | + } |
| 261 | + |
| 262 | + public JSONObject getFinalJSONObject(){ |
| 263 | + return final_object; |
| 264 | + } |
| 265 | + |
| 266 | + public CodeStats getCodeStats() { |
| 267 | + return cs; |
| 268 | + } |
| 269 | +} |
0 commit comments