List of usage examples for java.util HashSet toString
public String toString()
From source file:web.CarryoneditController.java
/** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException/*from w ww . j a v a2 s .c o m*/ * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest", e); } /** * Error checking, don't check for session management * as mini album can be viewed out of session */ if (RegexStrUtil.isNull(login) && RegexStrUtil.isNull(member)) { return handleError("Login & member are null, CarryoneditController"); } String category = request.getParameter(DbConstants.CATEGORY); int catVal = 0; if (!RegexStrUtil.isNull(category)) { if (category.equals(DbConstants.FILE_CATEGORY)) { if (!GlobalConst.hddomain.contains(DbConstants.INDIA_CENTURY)) { if (!WebUtil.isLicenseProfessional(login) && !WebUtil.isLicenseProfessional(member)) { return handleError("Cannot access user file features in deluxe version. member = " + member + " login = " + login); } } catVal = 4; } else { if (category.equals(DbConstants.PHOTO_CATEGORY)) { catVal = 1; } else { return handleError("invalid category, CarryoneditController"); } } } else { return handleError("Category is null for CarryoneditController"); } /** * gets the daomapper */ if (getDaoMapper() == null) { return handleError("DaoMapper is null in carryon edit."); } String pageNum = request.getParameter(DbConstants.PAGE_NUM); String published = request.getParameter(DbConstants.PUBLISHED); Userpage cobrand = null; /** * logged in user, accessing another members files or photos * myself = false * logged in user, accessing own files or photos, * myself = true */ boolean myself = false; if (!RegexStrUtil.isNull(login)) { if (!RegexStrUtil.isNull(member) && login.equals(member)) { myself = true; } else { if (RegexStrUtil.isNull(member)) { myself = true; } } } /** * display information about the files, if the category !=1 (files) */ Displaypage displayPage = null; DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE); if (displayDao == null) { return handleError("displayDao is null in carryon edit for login " + login); } boolean displayPhotos, displayFiles; displayPhotos = displayFiles = false; try { if (myself) { displayPage = displayDao.getDisplaypage(login, DbConstants.READ_FROM_MASTER); } else { displayPage = displayDao.getDisplaypage(member, DbConstants.READ_FROM_SLAVE); } } catch (BaseDaoException e) { return handleError("Exception occurred in getDisplaypage(), CarryoneditController ", e); } if ((displayPage != null) && (displayPage.getValue(DbConstants.FILES).equals("1"))) { displayFiles = true; } if ((displayPage != null) && (displayPage.getValue(DbConstants.PHOTOS).equals("1"))) { displayPhotos = true; } // DbConstants.PHOTO_CATEGORY if (!myself && (catVal == 1) && !displayPhotos) { return handleError("member does not give access to display photos to others" + member); } // DbConstants.FILES if (!myself && (catVal == 4) && !displayFiles) { return handleError("member does not give access to display files to others" + member); } CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleUserpageError("CobrandDao is null, CarryoneditController"); } CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null in carryon edit."); } List carryon = null; List tagList = null; HashSet tagSet = null; Hdlogin memberInfo = null; try { //if (!RegexStrUtil.isNull(login) && (!RegexStrUtil.isNull(member)) && (login.equals(member)) ) { if (myself) { if (loginInfo != null) { cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID)); carryon = carryonDao.getCarryonByCategory(loginInfo.getValue(DbConstants.LOGIN_ID), category, DbConstants.READ_FROM_SLAVE); tagList = carryonDao.getTags(loginInfo.getValue(DbConstants.LOGIN_ID), DbConstants.READ_FROM_SLAVE); tagSet = carryonDao.getUniqueTags(tagList); } memberInfo = loginInfo; } else { if (!RegexStrUtil.isNull(member)) { MemberDao memberDao = (MemberDao) getDaoMapper().getDao(DbConstants.MEMBER); if (memberDao == null) { return handleError("memberDao is null in CarryoeditController, for member= " + member); } memberInfo = memberDao.getMemberInfo(member); if (memberInfo != null) { cobrand = cobrandDao.getUserCobrand(memberInfo.getValue(DbConstants.LOGIN_ID)); carryon = carryonDao.getCarryonByCategory(memberInfo.getValue(DbConstants.LOGIN_ID), category, DbConstants.READ_FROM_SLAVE); tagList = carryonDao.getTags(memberInfo.getValue(DbConstants.LOGIN_ID), DbConstants.READ_FROM_SLAVE); tagSet = carryonDao.getUniqueTags(tagList); } } else { return handleError("Member is null in CarryoneditController"); } } } catch (BaseDaoException e) { return handleError( "Exception occurred in getCarryonByCategory(), category = + " + category + " in carryon edit ", e); } if (carryon == null) { return handleError("carryon is null, CarryoneditController."); } /** * editphotos/ editfiles - views resolved to the name of the jsp using ViewResolver */ String viewName = null; if (catVal == 1) { viewName = DbConstants.EDIT_PHOTOS; } else { viewName = DbConstants.EDIT_FILES; } Map myModel = new HashMap(); if (memberInfo != null) { myModel.put(DbConstants.MEMBER_INFO, memberInfo); } myModel.put(DbConstants.LOGIN_INFO, loginInfo); if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } myModel.put(DbConstants.PAGE_NUM, pageNum); myModel.put(DbConstants.PUBLISHED, published); myModel.put(DbConstants.DISPLAY_PAGE, displayPage); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); myModel.put(viewName, carryon); return new ModelAndView(viewName, "model", myModel); }
From source file:web.ViewphotosController.java
/** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException/* www .j av a 2 s . co m*/ * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /** * For subscription model, don't show unless the user has session */ try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in ViewtphotosController", e); } if (WebUtil.isProductPremiumSubscription()) { outOfSession(request, response); } if (getDaoMapper() == null) { handleError("DaoMapper is null, ViewtphotosController."); } List photoHitsList = null; CarryonDao carryonDao = (CarryonDao) daoMapper.getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null in ViewphotosController"); } /** * admin can search in any business. */ boolean isBizAware = false; String bid = null; if (WebUtil.isProductPremiumSubscription()) { if (!RegexStrUtil.isNull(login)) { if (!DiaryAdmin.isDiaryAdmin(login)) { isBizAware = true; } } if (userpage != null) { bid = userpage.getValue(DbConstants.BID); } } HashSet tagSet = null; if (isBizAware) { try { if (!RegexStrUtil.isNull(bid)) { photoHitsList = carryonDao.getCarryonHitsBizAware(bid, DbConstants.READ_FROM_SLAVE); } } catch (BaseDaoException e) { return handleError( "Exception in either getTopHitsBizAware()/getRecentBlogsBizAware/getPopularBlogsBizAware", e); } } else { try { photoHitsList = carryonDao.getCarryonHits(); if (photoHitsList != null) { tagSet = carryonDao.getUniqueTags(photoHitsList); } } catch (BaseDaoException e) { return handleError("Exception in either getCarryonHits()/getUniqueTags() in carryonDao", e); } } DirectoryDao dirDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY); if (dirDao == null) { return handleError("dirDao is null in ViewphotosController"); } DirectoryStreamBlobDao dirStreamBlobDao = (DirectoryStreamBlobDao) daoMapper.getDao(DbConstants.DIR_BLOB); if (dirStreamBlobDao == null) { return handleError("dirStreamBlobDao is null in ViewphotosController"); } HashSet dirBlobResult = null; if (tagSet != null) { SearchDao searchDao = (SearchDao) daoMapper.getDao(DbConstants.SEARCH); if (searchDao == null) { return handleError("searchDao is null, ViewphotosController"); } if (rbDirectoryExists.equals("1")) { try { List dirBlobTags = dirStreamBlobDao.get10Tags(DbConstants.READ_FROM_SLAVE); if (dirBlobTags != null && dirBlobTags.size() > 0) { dirBlobResult = dirDao.getDirBlobsFromTags(new HashSet(dirBlobTags)); HashSet tagSet2 = carryonDao.getUniqueTags(dirBlobTags); tagSet = sqlSearch.getUniqueTags(tagSet, tagSet2); } } catch (BaseDaoException e) { return handleError("Exception in either searchDirectoryBlobs, ViewphotosController", e); } } } Userpage cobrand = null; CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleError("CobrandDao is null, ViewphotosController"); } if (loginInfo != null) { try { cobrand = cobrandDao.getUserCobrand(loginInfo.getValue(DbConstants.LOGIN_ID)); } catch (BaseDaoException e) { return handleError("cobrand is null, ViewphotosController.", e); } } String viewName = DbConstants.PHOTOS; Map myModel = new HashMap(); myModel.put(DbConstants.TOP_CARRYON, photoHitsList); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.TAG_LIST, tagSet); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.LOGIN_INFO, loginInfo); if (rbDirectoryExists.equals("1") && (dirBlobResult != null)) { myModel.put(DbConstants.DIR_BLOB, dirBlobResult); } if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } if (!RegexStrUtil.isNull(login)) { myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); } return new ModelAndView(viewName, "model", myModel); }
From source file:web.SlideshowController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* www. ja v a2 s.c om*/ ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest"); } String member = request.getParameter(DbConstants.MEMBER); if (RegexStrUtil.isNull(member)) { return handleError("member or photNumStr is null. Forwarding to " + member + "SlideshowController"); } member = RegexStrUtil.goodId(member); Hdlogin memberInfo = null; MemberDao memberDao = (MemberDao) daoMapper.getDao(DbConstants.MEMBER); if (memberDao == null) { return handleError("MemberDao is null, SlideshowController, login, " + login); } try { memberInfo = memberDao.getMemberInfo(member); } catch (BaseDaoException e) { return handleError("getMemberInfo(member) exception in SlideshowController, member=" + member, e); } if (memberInfo == null) { return handleError("memberInfo is null, in SlideshowController" + member); } /** * start the slide show */ if (getDaoMapper() == null) { return handleError("DaoMapper is null in SlideshowController, member " + member); } CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null, SlideshowController for member " + member); } /** * retrieve the update blob stream and other blobs */ List carryon = null; List tagList = null; HashSet tagSet = null; try { carryon = carryonDao.getCarryonByCategory(memberInfo.getValue(DbConstants.LOGIN_ID), DbConstants.PHOTO_CATEGORY, DbConstants.READ_FROM_SLAVE); tagList = carryonDao.getTags(memberInfo.getValue(DbConstants.LOGIN_ID), DbConstants.READ_FROM_SLAVE); tagSet = carryonDao.getUniqueTags(tagList); } catch (BaseDaoException e) { return handleError("Exception occurred in getCarryonByCategory() member, " + member, e); } if (carryon == null) { return handleError("carryon is null for SlideshowController, member = " + member); } /** * check if this photo exists */ int photoNum = 0; int nextPhotoNum = 0; int prevPhotoNum = 0; String goPhoto = request.getParameter(DbConstants.GOTO_PHOTO); if (!RegexStrUtil.isNull(goPhoto)) { String showphoto = request.getParameter(DbConstants.SHOW_PHOTO); if (!RegexStrUtil.isNull(showphoto)) { photoNum = new Integer(showphoto).intValue(); } } else { String photoNumStr = request.getParameter(DbConstants.PHOTO_NUM); if (!RegexStrUtil.isNull(photoNumStr)) { photoNum = new Integer(photoNumStr).intValue(); } } String timerStr = request.getParameter(DbConstants.TIMER); if (RegexStrUtil.isNull(timerStr)) { timerStr = "0"; } String fn = request.getParameter(DbConstants.FNDOTX); if (carryon.size() == 1) { photoNum = nextPhotoNum = prevPhotoNum = 0; } else { if (photoNum >= carryon.size()) { photoNum = 0; nextPhotoNum = photoNum + 1; prevPhotoNum = carryon.size() - 1; } else { nextPhotoNum = photoNum + 1; if (photoNum != 0) { prevPhotoNum = photoNum - 1; ; } else { prevPhotoNum = carryon.size() - 1; } } } CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleUserpageError("CobrandDao is null, SlideshowController"); } Userpage cobrand = cobrandDao.getUserCobrand(memberInfo.getValue(DbConstants.LOGIN_ID)); String url = ""; Map myModel = new HashMap(); if (!RegexStrUtil.isNull(fn)) { String beg = request.getParameter("count"); if (beg != null) { int count = new Integer(beg).intValue(); if ((count > 0) && count <= carryon.size()) { count--; String newBeg = "-1"; if (count >= 0) { newBeg = new Integer(count).toString(); } StringBuffer myUrl = new StringBuffer("<META HTTP-EQUIV=\"Refresh\" CONTENT=\""); myUrl.append(timerStr); myUrl.append("; URL="); myUrl.append("slideshow?member="); myUrl.append(member); myUrl.append("&photonum="); myUrl.append(nextPhotoNum); myUrl.append("&timer="); myUrl.append(timerStr); myUrl.append("&count="); myUrl.append(newBeg); myUrl.append("&fn.x="); myUrl.append(DbConstants.PLAY); myUrl.append("\">"); url = myUrl.toString(); } else { //lastone myModel.put("count", null); } } // beg != null } else { myModel.put("count", null); } /** * editphotos or editfiles - views resolved to the name of the jsp using ViewResolver */ String viewName = DbConstants.SLIDE_SHOW; myModel.put(viewName, carryon); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.SHARE_INFO, shareInfo); if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } StringBuffer sb = new StringBuffer(); sb.append(photoNum); myModel.put(DbConstants.PHOTO_NUM, sb.toString()); sb.delete(0, sb.length()); sb.append(nextPhotoNum); myModel.put(DbConstants.NEXT_NUM, sb.toString()); sb.delete(0, sb.length()); sb.append(prevPhotoNum); myModel.put(DbConstants.PREV_NUM, sb.toString()); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.TIMER, timerStr); myModel.put(DbConstants.URL, url); return new ModelAndView(viewName, "model", myModel); //myModel.put(DbConstants.FN, fn); }
From source file:web.SlidesController.java
/** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException/*from ww w.j a va 2 s.co m*/ * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in handleRequest"); } if (getDaoMapper() == null) { return handleError("DaoMapper is null in SlidesController, member " + member); } String member = request.getParameter(DbConstants.MEMBER); if (RegexStrUtil.isNull(member)) { return handleError("member is null, Forwarding to " + member + "SlidesController"); } member = RegexStrUtil.goodId(member); Hdlogin memberInfo = null; MemberDao memberDao = (MemberDao) daoMapper.getDao(DbConstants.MEMBER); if (memberDao == null) { return handleError("MemberDao is null, SlidesController, login, " + login); } try { memberInfo = memberDao.getMemberInfo(member); } catch (BaseDaoException e) { return handleError("getMemberInfo(member) exception in SlidesController, member=" + member, e); } if (memberInfo == null) { return handleError("memberInfo is null, in SlidesController" + member); } DisplaypageDao displayDao = (DisplaypageDao) getDaoMapper().getDao(DbConstants.DISPLAY_PAGE); if (displayDao == null) { return handleError("DisplaypageDao is null, " + member); } Displaypage uDisplaypage = null; try { uDisplaypage = displayDao.getDisplaypage(member); } catch (BaseDaoException e) { return handleError("Exception occurred in getMyDisplayInfo(), for member, " + member, e); } if (uDisplaypage == null) { return handleUserpageError("displaypage is null" + member); } /** * if the user has not published photos, check: * 1. Is this login same as member? * 2. Is the login in session? */ String published = uDisplaypage.getValue(DbConstants.PHOTOS); if (!RegexStrUtil.isNull(published) && (published.equals("0"))) { if (!RegexStrUtil.isNull(login) && !login.equals(member)) { return handleUserpageError(login + " user cannot access slideshow of this member =" + member); } outOfSession(request, response); } /** * start the slide show */ CarryonDao carryonDao = (CarryonDao) getDaoMapper().getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null, SlidesController for member " + member); } /** * retrieve the update blob stream and other blobs */ List carryon = null; List tagList = null; HashSet tagSet = null; try { carryon = carryonDao.getCarryonByCategory(memberInfo.getValue(DbConstants.LOGIN_ID), DbConstants.PHOTO_CATEGORY, DbConstants.READ_FROM_SLAVE); tagList = carryonDao.getTags(memberInfo.getValue(DbConstants.LOGIN_ID), DbConstants.READ_FROM_SLAVE); tagSet = carryonDao.getUniqueTags(tagList); } catch (BaseDaoException e) { return handleError("Exception occurred in getCarryonByCategory() member, " + member, e); } if (carryon == null) { return handleError("carryon is null for SlidesController, member = " + member); } /** * check if this photo exists */ int photoNum = 0; int nextPhotoNum = 0; int prevPhotoNum = 0; String goPhoto = request.getParameter(DbConstants.GOTO_PHOTO); if (!RegexStrUtil.isNull(goPhoto)) { String showphoto = request.getParameter(DbConstants.SHOW_PHOTO); if (!RegexStrUtil.isNull(showphoto)) { photoNum = new Integer(showphoto).intValue(); } } else { String photoNumStr = request.getParameter(DbConstants.PHOTO_NUM); if (!RegexStrUtil.isNull(photoNumStr)) { photoNum = new Integer(photoNumStr).intValue(); } } String timerStr = request.getParameter(DbConstants.TIMER); if (RegexStrUtil.isNull(timerStr)) { timerStr = "0"; } String fn = request.getParameter(DbConstants.FNDOTX); if (carryon.size() == 1) { photoNum = nextPhotoNum = prevPhotoNum = 0; } else { if (photoNum >= carryon.size()) { photoNum = 0; nextPhotoNum = photoNum + 1; prevPhotoNum = carryon.size() - 1; } else { nextPhotoNum = photoNum + 1; if (photoNum != 0) { prevPhotoNum = photoNum - 1; ; } else { prevPhotoNum = carryon.size() - 1; } } } CobrandDao cobrandDao = (CobrandDao) getDaoMapper().getDao(DbConstants.COBRAND); if (cobrandDao == null) { return handleUserpageError("CobrandDao is null, SlidesController"); } Userpage cobrand = cobrandDao.getUserCobrand(memberInfo.getValue(DbConstants.LOGIN_ID)); String url = ""; Map myModel = new HashMap(); if (!RegexStrUtil.isNull(fn)) { String beg = request.getParameter("count"); if (beg != null) { int count = new Integer(beg).intValue(); if ((count > 0) && count <= carryon.size()) { count--; String newBeg = "-1"; if (count >= 0) { newBeg = new Integer(count).toString(); } StringBuffer myUrl = new StringBuffer("<META HTTP-EQUIV=\"Refresh\" CONTENT=\""); myUrl.append(timerStr); myUrl.append("; URL="); myUrl.append("slides?member="); myUrl.append(member); myUrl.append("&photonum="); myUrl.append(nextPhotoNum); myUrl.append("&timer="); myUrl.append(timerStr); myUrl.append("&count="); myUrl.append(newBeg); myUrl.append("&fn.x="); myUrl.append(DbConstants.PLAY); myUrl.append("\">"); url = myUrl.toString(); } else { //lastone myModel.put("count", null); } } // beg != null } else { myModel.put("count", null); } /** * editphotos or editfiles - views resolved to the name of the jsp using ViewResolver */ String viewName = DbConstants.SLIDES; myModel.put(viewName, carryon); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.PUBLISHED, published); if (tagSet != null) { myModel.put(DbConstants.USER_TAGS, RegexStrUtil.goodText(tagSet.toString())); } StringBuffer sb = new StringBuffer(); sb.append(photoNum); myModel.put(DbConstants.PHOTO_NUM, sb.toString()); sb.delete(0, sb.length()); sb.append(nextPhotoNum); myModel.put(DbConstants.NEXT_NUM, sb.toString()); sb.delete(0, sb.length()); sb.append(prevPhotoNum); myModel.put(DbConstants.PREV_NUM, sb.toString()); myModel.put(DbConstants.COBRAND, cobrand); myModel.put(DbConstants.TIMER, timerStr); myModel.put(DbConstants.URL, url); return new ModelAndView(viewName, "model", myModel); //myModel.put(DbConstants.FN, fn); }
From source file:web.Viewtop10Controller.java
/** * This method is called by the spring framework. The configuration * for this controller to be invoked is based on the pagetype and * is set in the urlMapping property in the spring config file. * * @param request the <code>HttpServletRequest</code> * @param response the <code>HttpServletResponse</code> * @throws ServletException//from ww w. j ava 2 s . com * @throws IOException * @return ModelAndView this instance is returned to spring */ public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /** * For subscription model don't show unless the user has session */ try { ModelAndView m = super.handleRequest(request, response); } catch (Exception e) { return handleError("error in Viewtop10Controller", e); } if (WebUtil.isProductPremiumSubscription()) { outOfSession(request, response); } if (getDaoMapper() == null) { handleError("DaoMapper is null, Viewtop10Controller."); } UserpageDao userpageDao = (UserpageDao) daoMapper.getDao(DbConstants.USER_PAGE); if (userpageDao == null) { return handleError("userpageDao is null in ToptenusersController"); } List recentUsers = null; List topUsers = null; List recentDirImages = null; List topDirs = null; List recentPhotos = null; List photoHitsList = null; List recentPersonalBlogs = null; List popularPersonalBlogs = null; HashSet tagSet = null; PblogDao pblogDao = (PblogDao) daoMapper.getDao(DbConstants.PERSONAL_BLOG); if (pblogDao == null) { return handleError("pblogDao is null in toptenblogsController"); } PblogTopicDao pblogTopicDao = (PblogTopicDao) daoMapper.getDao(DbConstants.PBLOG_TOPIC); if (pblogTopicDao == null) { return handleError("pblogTopicDao is null in toptenblogsController"); } MemberDao memberDao = (MemberDao) getDaoMapper().getDao(DbConstants.MEMBER); if (memberDao == null) { return handleError("memberDao is null pblogaddController"); } CarryonDao carryonDao = (CarryonDao) daoMapper.getDao(DbConstants.CARRYON); if (carryonDao == null) { return handleError("carryonDao is null in viewtop10Controller"); } DirectoryDao dirDao = (DirectoryDao) daoMapper.getDao(DbConstants.DIRECTORY); if (dirDao == null) { return handleError("dirDao is null in viewtop10Controller"); } /** * admin can search in any business. */ boolean isBizAware = false; HashSet blogTagSet = null; List randDirImages = null; String bid = null; if (WebUtil.isProductPremiumSubscription()) { if (!RegexStrUtil.isNull(login)) { if (!DiaryAdmin.isDiaryAdmin(login)) { isBizAware = true; } } if (userpage != null) { bid = userpage.getValue(DbConstants.BID); } } if (isBizAware) { try { if (!RegexStrUtil.isNull(bid)) { topUsers = userpageDao.getTopHitsBizAware(bid, DbConstants.READ_FROM_SLAVE); //recentPersonalBlogs = pblogDao.getRecentBlogsBizAware(bid, DbConstants.READ_FROM_SLAVE); recentPersonalBlogs = pblogTopicDao.getBizCurrentTopics(bid, DbConstants.READ_FROM_SLAVE); if (recentPersonalBlogs != null) { for (int i = 0; i < recentPersonalBlogs.size(); i++) { if (recentPersonalBlogs.get(i) != null) { String userId = ((Blog) recentPersonalBlogs.get(i)).getValue(DbConstants.BLOG_ID); String photoId = memberDao.getPhotoEntryId(userId); ((Blog) recentPersonalBlogs.get(i)).setValue(DbConstants.PHOTO_ID, photoId); } } } popularPersonalBlogs = pblogDao.getPopularBlogsBizAware(bid, DbConstants.READ_FROM_SLAVE); photoHitsList = carryonDao.getCarryonHitsBizAware(bid, DbConstants.READ_FROM_SLAVE); } } catch (BaseDaoException e) { return handleError( "Exception in either getTopHitsBizAware()/getRecentBlogsBizAware/getPopularBlogsBizAware", e); } } else { try { topUsers = userpageDao.getTopHits(DbConstants.READ_FROM_SLAVE); recentUsers = userpageDao.getRecentUsers(DbConstants.READ_FROM_SLAVE); //recentPersonalBlogs = pblogDao.getRecentBlogs(); recentPersonalBlogs = pblogTopicDao.getCurrentTopics(DbConstants.READ_FROM_SLAVE); if (recentPersonalBlogs != null && recentPersonalBlogs.size() > 0) { for (int i = 0; i < recentPersonalBlogs.size(); i++) { if (recentPersonalBlogs.get(i) != null) { String userId = ((Blog) recentPersonalBlogs.get(i)).getValue(DbConstants.BLOG_ID); String photoId = memberDao.getPhotoEntryId(userId); ((Blog) recentPersonalBlogs.get(i)).setValue(DbConstants.PHOTO_ID, photoId); } } } popularPersonalBlogs = pblogDao.getPopularBlogs(); if (!RegexStrUtil.isNull(GlobalConst.PortalServer)) { if (GlobalConst.hddomain.contains(GlobalConst.PortalServer)) { recentDirImages = dirDao.getRecentSelectDirImages(DbConstants.INDIA_CENTURY, DbConstants.READ_FROM_MASTER); } else { recentDirImages = dirDao.getRecentDirImages(DbConstants.READ_FROM_MASTER); } } randDirImages = dirDao.getRandDirImages(DbConstants.PHOTO_CATEGORY_INT, GlobalConst.directoryId, DbConstants.READ_FROM_MASTER); photoHitsList = carryonDao.getCarryonHits(); recentPhotos = carryonDao.getRecentCarryon(DbConstants.READ_FROM_SLAVE, DbConstants.PHOTO_CATEGORY); if (photoHitsList != null) { tagSet = carryonDao.getUniqueTags(photoHitsList); } if (recentPersonalBlogs != null) { blogTagSet = pblogDao.getPblogTags(recentPersonalBlogs); } if (popularPersonalBlogs != null) { HashSet tagSet2 = pblogDao.getPblogTags(popularPersonalBlogs); if (tagSet2 != null) { blogTagSet = sqlSearch.getUniqueTags(blogTagSet, tagSet2); } } } catch (BaseDaoException e) { return handleError("Exception in either getRecentBlogs()/getPopularBlogs() in pblogDao", e); } } //if (!RegexStrUtil.isNull(login)) { try { if (rbDirectoryExists.equals("1")) { topDirs = userpageDao.getTopDirs(DbConstants.READ_FROM_MASTER); if (!RegexStrUtil.isNull(GlobalConst.PortalServer)) { if (GlobalConst.hddomain.contains(GlobalConst.PortalServer)) { recentDirImages = dirDao.getRecentSelectDirImages(DbConstants.INDIA_CENTURY, DbConstants.READ_FROM_MASTER); } else { recentDirImages = dirDao.getRecentDirImages(DbConstants.READ_FROM_MASTER); } } if (topDirs != null) { topDirs = dirDao.setDirPhotos(topDirs); } } } catch (BaseDaoException e) { return handleError("Exception in either getTopDirs()", e); } //} String viewName = "viewtop10"; Map myModel = new HashMap(); myModel.put(DbConstants.RECENT_USERS, recentUsers); myModel.put(DbConstants.RECENT_CARRYON, recentPhotos); myModel.put(DbConstants.RECENT_DIR_IMAGES, recentDirImages); myModel.put(DbConstants.RAND_DIR_IMAGES, randDirImages); myModel.put(DbConstants.RECENT_BLOGS, recentPersonalBlogs); myModel.put(DbConstants.POPULAR_BLOGS, popularPersonalBlogs); myModel.put(DbConstants.TOP_USERS, topUsers); myModel.put(DbConstants.TOP_CARRYON, photoHitsList); myModel.put(DbConstants.DIR_EXISTS, rbDirectoryExists); myModel.put(DbConstants.USER_PAGE, userpage); myModel.put(DbConstants.SHARE_INFO, shareInfo); myModel.put(DbConstants.VISITOR_PAGE, memberUserpage); String dirTagString = null; if (rbDirectoryExists.equals("1")) { if (topDirs != null && topDirs.size() > 0) { dirTagString = RegexStrUtil.getDirKeysAsString(topDirs); } myModel.put(DbConstants.TOP_DIRS, topDirs); } StringBuffer sb = new StringBuffer(); if (sb != null) { if (tagSet != null && tagSet.size() > 0) { sb.append(RegexStrUtil.goodText(tagSet.toString())); sb.append(" "); } if (blogTagSet != null) { sb.append(RegexStrUtil.getUsertagsAsString(blogTagSet)); sb.append(" "); } if (!RegexStrUtil.isNull(dirTagString)) { sb.append(dirTagString); } myModel.put(DbConstants.USER_TAGS, sb.toString()); } if (!RegexStrUtil.isNull(login)) { myModel.put(DbConstants.LOGIN_INFO, loginInfo); myModel.put(DbConstants.BUSINESS_EXISTS, isBizExists(login)); } return new ModelAndView(viewName, "model", myModel); }
From source file:it.cnr.isti.hpc.dexter.disambiguation.TurkishEntityDisambiguator.java
@Override public EntityMatchList disambiguate(DexterLocalParams localParams, SpotMatchList sml) { entityScoreMap = new HashMap<String, EntityScores>(); selectedEntities = new HashSet<String>(); Multiset<String> entityFrequencyMultiset = HashMultiset.create(); EntityMatchList entities = sml.getEntities(); String inputText = localParams.getParams().get("text"); String algorithm = Property.getInstance().get("algorithm"); String ambigious = Property.getInstance().get("algorithm.ambigious"); List<Token> inputTokens = Zemberek.getInstance().disambiguateFindTokens(inputText, false, true); List<Double> documentVector = DescriptionEmbeddingAverage.getAverageVectorList(inputText); Multiset<String> inputTokensMultiset = HashMultiset.create(); for (Token token : inputTokens) { inputTokensMultiset.add(token.getMorphText()); }//from w w w . j ava 2 s . c o m Multiset<String> domainMultiset = HashMultiset.create(); Multiset<String> typeMultiset = HashMultiset.create(); HashMap<String, Double> entitySimMap = new HashMap<String, Double>(); // if (printCandidateEntities) { // printEntities(entities); // } HashSet<String> words = new HashSet<String>(); Multiset<String> leskWords = HashMultiset.create(); // first pass for finding number of types and domains for (int i = 0; i < entities.size(); i++) { EntityMatch em = entities.get(i); String id = em.getId(); if (!entityFrequencyMultiset.contains(id)) { entityFrequencyMultiset.add(id); Entity entity = em.getEntity(); words.add(entity.getShingle().getText()); String type = entity.getPage().getType(); if (type != null && type.length() > 0) { typeMultiset.add(type); } String domain = entity.getPage().getDomain(); if (domain != null && domain.length() > 0) { domainMultiset.add(domain); } String desc = entity.getPage().getDescription(); List<Token> tokens = Zemberek.getInstance().disambiguateFindTokens(desc, false, true); for (Token token : tokens) { leskWords.add(token.getMorphText()); } } else { entityFrequencyMultiset.add(id); } } int maxDomainCount = 0; for (String domain : Multisets.copyHighestCountFirst(domainMultiset).elementSet()) { maxDomainCount = domainMultiset.count(domain); break; } int maxTypeCount = 0; for (String type : Multisets.copyHighestCountFirst(typeMultiset).elementSet()) { maxTypeCount = typeMultiset.count(type); break; } double maxSuffixScore = 0, maxLeskScore = 0, maxSimpleLeskScore = 0, maxLinkScore = 0, maxHashInfoboxScore = 0, maxwordvecDescriptionLocalScore = 0, maxHashDescriptionScore = 0, maxPopularityScore = 0, maxWordvectorAverage = 0, maxWordvecLinksScore = 0; // second pass compute similarities between entities in a window int currentSpotIndex = -1; SpotMatch currentSpot = null; for (int i = 0; i < entities.size(); i++) { EntityMatch em = entities.get(i); SpotMatch spot = em.getSpot(); if (currentSpot == null || spot != currentSpot) { currentSpotIndex++; currentSpot = spot; } String id = em.getId(); Entity entity = entities.get(i).getEntity(); EntityPage page = entities.get(i).getEntity().getPage(); String domain = page.getDomain(); String type = page.getType(); Shingle shingle = entity.getShingle(); /* windowing algorithms stars */ int left = currentSpotIndex - window; int right = currentSpotIndex + window; if (left < 0) { right -= left; left = 0; } if (right > sml.size()) { left += (sml.size()) - right; right = sml.size(); if (left < 0) { left = 0; } } double linkScore = 0, hashInfoboxScore = 0, wordvecDescriptionLocalScore = 0, hashDescriptionScore = 0, wordvecLinksScore = 0; for (int j = left; j < right; j++) { SpotMatch sm2 = sml.get(j); EntityMatchList entities2 = sm2.getEntities(); for (EntityMatch em2 : entities2) { String id2 = em2.getId(); EntityPage page2 = em2.getEntity().getPage(); int counter = 0; if (!ambigious.equals("true")) { for (EntityMatch entityMatch : entities2) { if (entityMatch.getId().startsWith("w")) { counter++; } } } if ((ambigious.equals("true") || counter == 1) && em.getSpot() != em2.getSpot() && !id.equals(id2)) { // Link Similarity calculation starts double linkSim = 0; if (id.startsWith("w") && id2.startsWith("w")) { if (entitySimMap.containsKey("link" + id + id2)) { linkSim = entitySimMap.get("link" + id + id2); } else { HashSet<String> set1 = Sets.newHashSet(page.getLinks().split(" ")); HashSet<String> set2 = Sets.newHashSet(page2.getLinks().split(" ")); linkSim = JaccardCalculator.calculateSimilarity(set1, set2); entitySimMap.put("link" + id + id2, linkSim); } linkScore += linkSim; // Link Similarity calculation ends } // Entity embedding similarity calculation starts double eeSim = 0; if (id.startsWith("w") && id2.startsWith("w")) { if (entitySimMap.containsKey("ee" + id + id2)) { eeSim = entitySimMap.get("ee" + id + id2); } else { eeSim = EntityEmbeddingSimilarity.getInstance().getSimilarity(page, page2); entitySimMap.put("ee" + id + id2, eeSim); } hashInfoboxScore += eeSim; } double w2veclinksSim = 0; if (id.startsWith("w") && id2.startsWith("w")) { if (entitySimMap.containsKey("wl" + id + id2)) { w2veclinksSim = entitySimMap.get("wl" + id + id2); } else { w2veclinksSim = AveragePooling.getInstance().getSimilarity(page.getWord2vec(), page2.getWord2vec()); entitySimMap.put("wl" + id + id2, w2veclinksSim); } wordvecLinksScore += w2veclinksSim; } // Entity embedding similarity calculation ends // Description word2vec similarity calculation // starts double word2vecSim = 0; if (entitySimMap.containsKey("w2v" + id + id2)) { word2vecSim = entitySimMap.get("w2v" + id + id2); } else { word2vecSim = AveragePooling.getInstance().getSimilarity(page2.getDword2vec(), page.getDword2vec()); entitySimMap.put("w2v" + id + id2, word2vecSim); } wordvecDescriptionLocalScore += word2vecSim; // Description word2vec similarity calculation ends // Description autoencoder similarity calculation // starts double autoVecSim = 0; if (entitySimMap.containsKey("a2v" + id + id2)) { autoVecSim = entitySimMap.get("a2v" + id + id2); } else { autoVecSim = AveragePooling.getInstance().getSimilarity(page2.getDautoencoder(), page.getDautoencoder()); entitySimMap.put("a2v" + id + id2, autoVecSim); } hashDescriptionScore += autoVecSim; // Description autoencoder similarity calculation // ends } } } if (linkScore > maxLinkScore) { maxLinkScore = linkScore; } if (hashInfoboxScore > maxHashInfoboxScore) { maxHashInfoboxScore = hashInfoboxScore; } if (wordvecDescriptionLocalScore > maxwordvecDescriptionLocalScore) { maxwordvecDescriptionLocalScore = wordvecDescriptionLocalScore; } if (hashDescriptionScore > maxHashDescriptionScore) { maxHashDescriptionScore = hashDescriptionScore; } if (wordvecLinksScore > maxWordvecLinksScore) { maxWordvecLinksScore = wordvecLinksScore; } /* windowing algorithms ends */ double domainScore = 0; if (domainMultiset.size() > 0 && maxDomainCount > 1 && domainMultiset.count(domain) > 1) { domainScore = (double) domainMultiset.count(domain) / maxDomainCount; } double typeScore = 0; if (typeMultiset.size() > 0 && maxTypeCount > 1 && typeMultiset.count(type) > 1) { typeScore = (double) typeMultiset.count(type) / maxTypeCount; } if (typeBlackList.contains(type)) { typeScore /= 10; } double typeContentScore = 0; if (type.length() > 0 && StringUtils.containsIgnoreCase(words.toString(), type)) { typeContentScore = 1; } double typeClassifierScore = TypeClassifier.getInstance().predict(page, page.getTitle(), page.getType(), entity.getShingle().getSentence()); double wordvecDescriptionScore = AveragePooling.getInstance().getSimilarity(documentVector, page.getDword2vec()); if (wordvecDescriptionScore > maxWordvectorAverage) { maxWordvectorAverage = wordvecDescriptionScore; } double suffixScore = 0; if (type != null && type.length() > 0) { Set<String> suffixes = new HashSet<String>(); String t = entity.getTitle().toLowerCase(new Locale("tr", "TR")); for (int x = 0; x < entities.size(); x++) { EntityMatch e2 = entities.get(x); if (e2.getId().equals(entity.getId())) { suffixes.add(e2.getMention()); } } suffixes.remove(t); suffixes.remove(entity.getTitle()); // String inputTextLower = inputText.toLowerCase(new // Locale("tr", // "TR")); // while (inputTextLower.contains(t)) { // int start = inputTextLower.indexOf(t); // int end = inputTextLower.indexOf(" ", start + t.length()); // if (end > start) { // String suffix = inputTextLower.substring(start, end); // // .replaceAll("\\W", ""); // if (suffix.contains("'") // || (Zemberek.getInstance().hasMorph(suffix) // && !suffix.equals(t) && suffix.length() > 4)) { // suffixes.add(suffix); // } // inputTextLower = inputTextLower.substring(end); // } else { // break; // } // } if (suffixes.size() >= minSuffix) { for (String suffix : suffixes) { double sim = gd.calculateSimilarity(suffix, type); suffixScore += sim; } } } // String entitySuffix = page.getSuffix(); // String[] inputSuffix = shingle.getSuffix().split(" "); // for (int j = 0; j < inputSuffix.length; j++) { // if (entitySuffix.contains(inputSuffix[j])) { // suffixScore += 0.25f; // } // } if (suffixScore > maxSuffixScore) { maxSuffixScore = suffixScore; } // if (id.equals("w691538")) { // LOGGER.info(""); // } double letterCaseScore = 0; int lc = page.getLetterCase(); if (StringUtils.isAllLowerCase(em.getMention()) && lc == 0 && id.startsWith("t")) { letterCaseScore = 1; } else if (StringUtils.isAllUpperCase(em.getMention()) && lc == 1 && id.startsWith("w")) { letterCaseScore = 1; } else if (Character.isUpperCase(em.getMention().charAt(0)) && lc == 2 && id.startsWith("w")) { letterCaseScore = 1; } else if (StringUtils.isAllLowerCase(em.getMention()) && id.startsWith("t")) { letterCaseScore = 1; } double nameScore = 1 - LevenshteinDistanceCalculator.calculateDistance(page.getTitle(), Zemberek.removeAfterSpostrophe(em.getMention())); double popularityScore = page.getRank(); if (id.startsWith("w")) { popularityScore = Math.log10(popularityScore + 1); if (popularityScore > maxPopularityScore) { maxPopularityScore = popularityScore; } } double leskScore = 0, simpleLeskScore = 0; String desc = em.getEntity().getPage().getDescription(); if (desc != null) { List<Token> tokens = Zemberek.getInstance().disambiguateFindTokens(desc, false, true); for (Token token : tokens) { if (inputTokensMultiset.contains(token.getMorphText()) && !TurkishNLP.isStopWord(token.getMorphText())) { simpleLeskScore += inputTokensMultiset.count(token.getMorphText()); } if (leskWords.contains(token.getMorphText()) && !TurkishNLP.isStopWord(token.getMorphText())) { leskScore += leskWords.count(token.getMorphText()); } } leskScore /= Math.log(tokens.size() + 1); simpleLeskScore /= Math.log(tokens.size() + 1); if (leskScore > maxLeskScore) { maxLeskScore = leskScore; } if (simpleLeskScore > maxSimpleLeskScore) { maxSimpleLeskScore = simpleLeskScore; } if (!entityScoreMap.containsKey(id)) { EntityScores scores = new EntityScores(em, id, popularityScore, nameScore, letterCaseScore, suffixScore, wordvecDescriptionScore, typeContentScore, typeScore, domainScore, hashDescriptionScore, wordvecDescriptionLocalScore, hashInfoboxScore, linkScore, wordvecLinksScore, leskScore, simpleLeskScore, typeClassifierScore); entityScoreMap.put(id, scores); } else { EntityScores entityScores = entityScoreMap.get(id); entityScores.setHashInfoboxScore((entityScores.getHashInfoboxScore() + hashInfoboxScore) / 2); entityScores.setHashDescriptionScore( (entityScores.getHashInfoboxScore() + hashDescriptionScore) / 2); entityScores.setLinkScore((entityScores.getLinkScore() + linkScore) / 2); entityScores.setWordvecDescriptionLocalScore( (entityScores.getWordvecDescriptionLocalScore() + wordvecDescriptionLocalScore) / 2); entityScores .setWordvecLinksScore((entityScores.getWordvecLinksScore() + wordvecLinksScore) / 2); entityScores.setLeskScore((entityScores.getLeskScore() + leskScore) / 2); } } } /* normalization and total score calculation starts */ Set<String> set = new HashSet<String>(); for (int i = 0; i < entities.size(); i++) { EntityMatch em = entities.get(i); String id = em.getId(); EntityScores entityScores = entityScoreMap.get(id); if (set.contains(id)) { continue; } if (id.startsWith("w")) { if (maxLinkScore > 0 && entityScores.getLinkScore() > 0) { entityScores.setLinkScore(entityScores.getLinkScore() / maxLinkScore); } if (maxHashInfoboxScore > 0 && entityScores.getHashInfoboxScore() > 0) { entityScores.setHashInfoboxScore(entityScores.getHashInfoboxScore() / maxHashInfoboxScore); } if (maxWordvecLinksScore > 0 && entityScores.getWordvecLinksScore() > 0) { entityScores.setWordvecLinksScore(entityScores.getWordvecLinksScore() / maxWordvecLinksScore); } if (maxPopularityScore > 0 && entityScores.getPopularityScore() > 0) { entityScores.setPopularityScore(entityScores.getPopularityScore() / maxPopularityScore); } } if (maxwordvecDescriptionLocalScore > 0 && entityScores.getWordvecDescriptionLocalScore() > 0) { entityScores.setWordvecDescriptionLocalScore( entityScores.getWordvecDescriptionLocalScore() / maxwordvecDescriptionLocalScore); } if (maxHashDescriptionScore > 0 && entityScores.getHashDescriptionScore() > 0) { entityScores .setHashDescriptionScore(entityScores.getHashDescriptionScore() / maxHashDescriptionScore); } if (maxWordvectorAverage > 0 && entityScores.getWordvecDescriptionScore() > 0) { entityScores.setWordvecDescriptionScore( entityScores.getWordvecDescriptionScore() / maxWordvectorAverage); } if (maxLeskScore > 0 && entityScores.getLeskScore() > 0) { entityScores.setLeskScore(entityScores.getLeskScore() / maxLeskScore); } if (maxSimpleLeskScore > 0 && entityScores.getSimpleLeskScore() > 0) { entityScores.setSimpleLeskScore(entityScores.getSimpleLeskScore() / maxSimpleLeskScore); } if (maxSuffixScore > 0 && entityScores.getSuffixScore() > 0) { entityScores.setSuffixScore(entityScores.getSuffixScore() / maxSuffixScore); } set.add(id); } LOGGER.info("\t" + "id\tTitle\tURL\tScore\tPopularity\tName\tLesk\tSimpeLesk\tCase\tNoun\tSuffix\tTypeContent\tType\tDomain\twordvecDescription\twordvecDescriptionLocal\thashDescription\thashInfobox\tword2vecLinks\tLink\t\ttypeClassifier\tDescription"); for (int i = 0; i < entities.size(); i++) { EntityMatch em = entities.get(i); String id = em.getId(); EntityScores e = entityScoreMap.get(id); double wikiScore = 0; if (id.startsWith("w") && Character.isUpperCase(em.getMention().charAt(0))) { wikiScore = wikiWeight; } else if (id.startsWith("t") && Character.isLowerCase(em.getMention().charAt(0))) { wikiScore = wikiWeight; } // if(id.equals("w508792")){ // LOGGER.info(""); // } double totalScore = wikiScore + e.getPopularityScore() * popularityWeight + e.getNameScore() * nameWeight + e.getLeskScore() * leskWeight + e.getSimpleLeskScore() * simpleLeskWeight + e.getLetterCaseScore() * letterCaseWeight + e.getSuffixScore() * suffixWeight + e.getTypeContentScore() * typeContentWeight + e.getTypeScore() * typeWeight + e.getDomainScore() * domainWeight + e.getWordvecDescriptionScore() * wordvecDescriptionWeight + e.getWordvecDescriptionLocalScore() * wordvecDescriptionLocalWeight + e.getHashDescriptionScore() * hashDescriptionWeight + e.getHashInfoboxScore() * hashInfoboxWeight + e.getWordvecLinksScore() * word2vecLinksWeight + e.getLinkScore() * linkWeight + e.getTypeClassifierkScore() * typeClassifierkWeight; if (ranklib == true) { totalScore = RankLib.getInstance().score(e); } if (em.getEntity().getPage().getUrlTitle().contains("(")) { totalScore /= 2; } em.setScore(totalScore); e.setScore(totalScore); LOGGER.info("\t" + id + "\t" + em.getEntity().getPage().getTitle() + "\t" + em.getEntity().getPage().getUrlTitle() + "\t" + em.getScore() + "\t" + e.getPopularityScore() * popularityWeight + "\t" + e.getNameScore() * nameWeight + "\t" + e.getLeskScore() * leskWeight + "\t" + e.getSimpleLeskScore() * simpleLeskWeight + "\t" + e.getLetterCaseScore() * letterCaseWeight + "\t" + e.getSuffixScore() * suffixWeight + "\t" + e.getTypeContentScore() * typeContentWeight + "\t" + e.getTypeScore() * typeWeight + "\t" + e.getDomainScore() * domainWeight + "\t" + e.getWordvecDescriptionScore() * wordvecDescriptionWeight + "\t" + e.getWordvecDescriptionLocalScore() * wordvecDescriptionLocalWeight + "\t" + e.getHashDescriptionScore() * hashDescriptionWeight + "\t" + e.getHashInfoboxScore() * hashInfoboxWeight + "\t" + e.getWordvecLinksScore() * word2vecLinksWeight + "\t" + e.getLinkScore() * linkWeight + "\t" + e.getTypeClassifierkScore() * typeClassifierkWeight + "\t" + em.getEntity().getPage().getDescription()); } // if (annotateEntities) { // annotateEntities(localParams.getParams().get("originalText"), sml); // } EntityMatchList eml = new EntityMatchList(); for (SpotMatch match : sml) { EntityMatchList list = match.getEntities(); if (!list.isEmpty()) { list.sort(); eml.add(list.get(0)); selectedEntities.add(list.get(0).getId()); } } return eml; }
From source file:StreamFlusher.java
public Object visit(ASTnet_embed_rtn_subnets_func_call node, Object data) { // evaluate the argument, a regexp, leaving an Fst object on the stack node.jjtGetChild(0).jjtAccept(this, data); Fst baseFst = (Fst) (stack.pop());/*from w w w . j av a 2 s. co m*/ // Check and list dependencies (the subnetworks) // for the whole implied RTN, keep them in an ArrayList // (HashSet would be convenient, but you can't iterate through it // and add objects to it during the iteration). HashSet would keep // out duplicates automatically--it's a bit harder with ArrayList. ArrayList<String> dependencies = new ArrayList<String>(); // find all subnets referred to by the baseFst findDependencies(baseFst, dependencies); // The order of objects in the ArrayList is constant and starts at index 0 // Now loop through the ArrayList of dependencies, which is a set (no // duplicates) adding new dependencies as they appear // (use a for-loop so that the size can grow during iteration-- // I tried to use HashSet, but this proved impossible) String dep; // keep a set of dependencies that are not defined (any // undefined dependency is an error) HashSet<String> not_defined = new HashSet<String>(); for (int i = 0; i < dependencies.size(); i++) { dep = dependencies.get(i); // Look up the dependency name in the symbol table. Fst fst = (Fst) env.get(dep); if (fst == null) { // add it to the set of undefined dependencies not_defined.add(dep); continue; } // find any additional dependencies of this dependency findDependencies(fst, dependencies); } // if any dependencies are not defined, throw an exception if (!not_defined.isEmpty()) { throw new UndefinedIdException("Undefined networks: " + not_defined.toString()); } // Reaching here, the whole RTN grammar has been defined. // (All the required networks are available in the // symbol table.) // Create an Fst result that incorporates the subnetworks, // unioning them in (with special prefixes) with the base // network. // EmbeddedRtn is not destructive; copies baseFst // if it comes from a symbol table Fst resultFst = lib.EmbeddedRtn(baseFst, dependencies, "__SUBNETWORKS"); stack.push(resultFst); return data; }
From source file:StreamFlusher.java
public Object visit(ASTnet_expand_rtn_func_call node, Object data) { // syntax $^expandRtn(regexp) if (lib.isSapRtnConventions()) { throw new KleeneInterpreterException("$^expandRtn() is not yet implemented under SapRtnConventions"); }//from www .j a v a 2 s.c om // evaluate the one argument, a regexp, // leaving an Fst object on the stack node.jjtGetChild(0).jjtAccept(this, data); Fst baseFst = (Fst) (stack.pop()); int baseFstInt; if (baseFst.getFromSymtab()) { // then reach down into the AST to get the image String net_id = ((ASTnet_id) (node.jjtGetChild(0).jjtGetChild(0))).getImage(); baseFstInt = symmap.putsym("__" + net_id); } else { baseFstInt = -1000000; // KRB: magic number } // a HashSet would be more convenient, but you can't iterate through // it and add to it ArrayList<String> subnetReferences = new ArrayList<String>(); // find subnet references in the baseFst findSubnetReferences(baseFst, subnetReferences); // The order of objects in the ArrayList is constant and starts at index 0 // Now loop through the ArrayList of subnetReferences, adding new ones // as they appear // (use a for-loop so that the size can grow during iteration-- // I tried to use HashSet and an Iterator, but this proved impossible) // Collect a set of undefined networks (if any) HashSet<String> not_defined = new HashSet<String>(); String subnetName; Fst subFst; for (int i = 0; i < subnetReferences.size(); i++) { subnetName = subnetReferences.get(i); // Look up the subnet name in the symbol table. subFst = (Fst) env.get(subnetName); if (subFst == null) { // add it to the list not_defined.add(subnetName); continue; } // also look for subnet references in this subnet findSubnetReferences(subFst, subnetReferences); } // bail out here, with a useful Exception message, if any // of the required subnets are not defined. if (!not_defined.isEmpty()) { throw new UndefinedIdException("Failed RTN expansion, undefined networks: " + not_defined.toString()); } // Reaching here, the whole RTN grammar has been defined. // (All the required networks are available in the // symbol table.) Fst resultFst = lib.ExpandRtn(baseFst, baseFstInt, subnetReferences); stack.push(resultFst); return data; }
From source file:com.l2jfree.gameserver.gameobjects.L2Player.java
/** * Manage the delete task of a L2Player (Leave Party, Unsummon pet, Save its inventory in the database, Remove it from the world...).<BR><BR> * * <B><U> Actions</U> :</B><BR><BR> * <li>If the L2Player is in observer mode, set its position to its position before entering in observer mode </li> * <li>Set the online Flag to True or False and update the characters table of the database with online status and lastAccess </li> * <li>Stop the HP/MP/CP Regeneration task </li> * <li>Cancel Crafting, Attak or Cast </li> * <li>Remove the L2Player from the world </li> * <li>Stop Party and Unsummon Pet </li> * <li>Update database with items in its inventory and remove them from the world </li> * <li>Remove all L2Object from _knownObjects and _knownPlayer of the L2Creature then cancel Attak or Cast and notify AI </li> * <li>Close the connection with the client </li><BR><BR> * *///from w w w . j a v a 2 s. co m public void deleteMe() { final HashSet<L2Zone> before = getZonesPlayerIn(); if (getOnlineState() == ONLINE_STATE_DELETED) return; // Pause restrictions ObjectRestrictions.getInstance().pauseTasks(getObjectId()); abortCast(); abortAttack(); try { if (isFlying()) removeSkill(SkillTable.getInstance().getInfo(4289, 1)); } catch (Exception e) { _log.fatal(e.getMessage(), e); } try { L2ItemInstance flag = getInventory().getItemByItemId(9819); if (flag != null) { Fort fort = FortManager.getInstance().getFort(this); if (fort != null) FortSiegeManager.getInstance().dropCombatFlag(this); else { int slot = flag.getItem().getBodyPart(); getInventory().unEquipItemInBodySlotAndRecord(slot); destroyItem("CombatFlag", flag, null, true); } } } catch (Exception e) { _log.fatal(e.getMessage(), e); } // If the L2Player has Pet, unsummon it if (getPet() != null) { try { getPet().unSummon(this); // dead pet wasnt unsummoned, broadcast npcinfo changes (pet will be without owner name - means owner offline) if (getPet() != null) getPet().broadcastFullInfoImpl(0); } catch (Exception e) { _log.error(e.getMessage(), e); } // Return pet to the control item } // Cancel trade if (getActiveRequester() != null) { getActiveRequester().onTradeCancel(this); onTradeCancel(getActiveRequester()); cancelActiveTrade(); setActiveRequester(null); } // Check if the L2Player is in observer mode to set its position to its position before entering in observer mode if (inObserverMode()) getPosition().setXYZ(_obsX, _obsY, _obsZ); else if (isInAirShip()) getAirShip().oustPlayer(this); Castle castle = null; if (getClan() != null) { castle = CastleManager.getInstance().getCastleByOwner(getClan()); if (castle != null) castle.destroyClanGate(); } // Set the online Flag to True or False and update the characters table of the database with online status and lastAccess (called when login and logout) try { setOnlineStatus(false); } catch (Exception e) { _log.fatal(e.getMessage(), e); } // Stop the HP/MP/CP Regeneration task (scheduled tasks) try { stopAllTimers(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } GlobalRestrictions.playerDisconnected(this); try { setIsTeleporting(false); } catch (Exception e) { _log.fatal(e.getMessage(), e); } // Stop crafting, if in progress try { RecipeTable.getInstance().requestMakeItemAbort(this); } catch (Exception e) { _log.fatal(e.getMessage(), e); } try { setTarget(null); } catch (Exception e) { _log.fatal(e.getMessage(), e); } if (_throne != null) _throne.setOccupier(null); _throne = null; try { if (_fusionSkill != null) { abortCast(); } for (L2Creature character : getKnownList().getKnownCharacters()) if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this) character.abortCast(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } getEffects().stopAllEffects(true); // Remove from world regions zones L2WorldRegion oldRegion = getWorldRegion(); // Remove the L2Player from the world if (isVisible()) { try { decayMe(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } } if (oldRegion != null) oldRegion.removeFromZones(this); // If a Party is in progress, leave it (and festival party) if (isInParty()) { try { // If player is festival participant and it is in progress // notify party members that the player is not longer a participant. if (isFestivalParticipant() && SevenSignsFestival.getInstance().isFestivalInitialized()) { getParty().broadcastToPartyMembers( SystemMessage.sendString(getName() + " has been removed from the upcoming festival.")); } leaveParty(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } } else // if in party, already taken care of { L2PartyRoom room = getPartyRoom(); if (room != null) room.removeMember(this, false); } PartyRoomManager.getInstance().removeFromWaitingList(this); if (getClanId() != 0 && getClan() != null) { // Set the status for pledge member list to OFFLINE try { L2ClanMember clanMember = getClan().getClanMember(getName()); if (clanMember != null) clanMember.setPlayerInstance(null); } catch (Exception e) { _log.fatal(e.getMessage(), e); } } if (getActiveRequester() != null) { // Deals with sudden exit in the middle of transaction setActiveRequester(null); } // If the L2Player is a GM, remove it from the GM List if (isGM()) { try { GmListTable.deleteGm(this); } catch (Exception e) { _log.fatal(e.getMessage(), e); } } // remove player from instance and set spawn location if any try { if (isInInstance()) { final Instance inst = InstanceManager.getInstance().getInstance(getInstanceId()); if (inst != null) { inst.removePlayer(getObjectId()); final Location spawn = inst.getSpawnLoc(); if (spawn != null) { final int x = spawn.getX() + Rnd.get(-30, 30); final int y = spawn.getY() + Rnd.get(-30, 30); getPosition().setXYZ(x, y, spawn.getZ()); if (getPet() != null) // dead pet { getPet().teleToLocation(x, y, spawn.getZ()); // ??? unset pet's instance id, but not players getPet().decayMe(); getPet().spawnMe(); } } } } } catch (Exception e) { _log.fatal(e.getMessage(), e); } // Update database with items in its inventory and remove them from the world try { getInventory().deleteMe(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } // Update database with items in its warehouse and remove them from the world try { clearWarehouse(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } if (Config.WAREHOUSE_CACHE) WarehouseCacheManager.getInstance().remove(this); // Update database with items in its freight and remove them from the world try { clearFreight(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } try { clearDepositedFreight(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } // Remove all L2Object from _knownObjects and _knownPlayer of the L2Creature then cancel Attak or Cast and notify AI try { getKnownList().removeAllKnownObjects(); } catch (Exception e) { _log.fatal(e.getMessage(), e); } untransform(); if (getClanId() > 0) getClan().broadcastToOtherOnlineMembers(new PledgeShowMemberListUpdate(this), this); if (_snoopedPlayers.length > 0) { for (L2Player snooped : _snoopedPlayers) snooped.removeSnooper(this); _snoopedPlayers = L2Player.EMPTY_ARRAY; } if (_snoopers.length > 0) { broadcastSnoop(SystemChatChannelId.Chat_Normal, "", "*** Player " + getName() + " logged off ***"); for (L2Player snooper : _snoopers) snooper.removeSnooped(this); _snoopers = L2Player.EMPTY_ARRAY; } for (Integer objId : getFriendList().getFriendIds()) { L2Player friend = L2World.getInstance().findPlayer(objId); if (friend != null) { friend.sendPacket(new FriendList(friend)); friend.sendMessage("Friend: " + getName() + " has logged off."); } } MovementController.getInstance().remove(this); // Remove L2Object object from _allObjects of L2World, if still in it L2World.getInstance().removeObject(this); try { // To delete the player from L2World on crit during teleport ;) setIsTeleporting(false); L2World.getInstance().removeOnlinePlayer(this); } catch (RuntimeException e) { _log.fatal("deleteMe()", e); } RegionBBSManager.changeCommunityBoard(this, PlayerStateOnCommunity.NONE); //getClearableReference().clear(); LeakTaskManager.getInstance().add(this); SQLQueue.getInstance().run(); final HashSet<L2Zone> after = getZonesPlayerIn(); if (!after.isEmpty()) { _log.warn("Leaking zones before L2Player.deleteMe(): " + before.toString()); _log.warn("Leaking zones after L2Player.deleteMe(): " + after.toString()); } }