16 package cz.vutbr.fit.knot.annotations.modules.suggestionManager;
25 import cz.vutbr.fit.knot.annotations.entity.*;
41 import java.util.logging.Level;
42 import java.util.logging.Logger;
43 import javax.persistence.EntityManager;
44 import javax.persistence.EntityTransaction;
45 import javax.persistence.Query;
46 import javax.xml.xpath.XPathExpressionException;
47 import org.json.simple.JSONObject;
48 import org.json.simple.JSONValue;
49 import org.w3c.dom.Document;
113 super(
"SuggestionsManagerModuleThread");
114 this.requestInfo = request;
123 || requestInfo.getSession().getUser().getGroups() == null ||
requestInfo.
getSession().getUser().getGroups().isEmpty()
128 AnnotDocument doc = requestInfo.getSession().getSyncDocument();
143 String msg =
"Unknown exception in SuggestionManager: " + ex.getMessage();
144 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg, ex);
147 AppBean.getLockMaster().getDocumentLock(doc.
getId()).unlockForRead();
154 AppBean.getLockMaster().getDocumentLock(doc.
getId()).unlockForRead();
166 if (
AppBean.
getLockMaster().getSuggReqLock(requestInfo.getSession().getSyncDocument().getId()).lockForChange()) {
173 AppBean.getLockMaster().getSuggReqLock(
requestInfo.
getSession().getSyncDocument().getId()).unlockForChange();
180 requestInfo.getSession().addMessageTS(result);
181 requestInfo.getSession().notifyComet();
185 ArrayList<SuggestionLogEntry> rSugs =
new ArrayList<SuggestionLogEntry>();
186 ArrayList<SuggestionLogEntry> sSugs =
new ArrayList<SuggestionLogEntry>();
200 boolean logIt = AppBean.getLogGetAlternativesFor();
202 Iterator<Suggestion> sugIt = requestInfo.getAlternativesRequestedFor().iterator();
203 while (sugIt.hasNext()) {
205 AlternativeManager.activateAlternatives(
requestInfo, sug);
207 String msg =
"getAlternativesFor " + sug.getId() +
" for document " + requestInfo.getSession().getSyncDocument().getUri();
208 Logger.getLogger(SuggestionManager.class.getName()).log(Level.WARNING, msg);
212 requestInfo.getSession().addMessageTS(result);
213 requestInfo.getSession().notifyComet();
219 requestInfo.getSession().addMessageTS(result);
220 requestInfo.getSession().notifyComet();
240 ArrayList<Annotation> addedAnnotations =
new ArrayList<Annotation>();
241 ArrayList<Annotation> editedAnnotations =
new ArrayList<Annotation>();
242 addedAnnotations.addAll(requestInfo.getFlier().getAddedAnnotations());
243 editedAnnotations.addAll(requestInfo.getFlier().getEditedAnnotations());
247 ArrayList<Suggestion> suggestionsToChange = SugPersister.persist(
requestInfo, addedAnnotations, editedAnnotations, null,
true,
new ArrayList<AnnotType>());
248 AlternativeManager.confirmSuggestions(request, suggestionsToChange);
253 String result =
printSuggestionsDiff(requestInfo.getSession(), suggestionsToChange,
new ArrayList<AnnotType>());
254 requestInfo.getSession().addMessageTS(result);
255 requestInfo.clearConfirmedSuggestions();
256 requestInfo.getSession().notifyComet();
258 synchronized(AppBean.getSessions()){
259 Iterator<EditorSession> sIt = AppBean.getSessions().iterator();
260 while (sIt.hasNext()) {
262 if (es.
equals(requestInfo.getSession()) || es.
getSyncDocument() == null || !es.getSyncDocument().equals(request.getSession().getSyncDocument())) {
266 es.addMessageTS(result);
280 ArrayList<Suggestion> retArray =
new ArrayList<Suggestion>();
281 if(suggestion != null){
284 List attrObjects = suggestion.getAttributes();
285 if(attrObjects != null && !attrObjects.isEmpty()){
286 Iterator attrIt = attrObjects.iterator();
287 while(attrIt.hasNext()){
288 Object actualObject = (Object) attrIt.next();
293 SugLinkedAttribute currentLink = (SugLinkedAttribute)actualObject;
296 retArray.add(((Suggestion)currentLink.
getValue()));
301 SugNestedAttribute currentNested = (SugNestedAttribute)actualObject;
302 if (currentNested.
getValue() != null && currentNested.getValue() instanceof
Suggestion) {
303 retArray.add(((Suggestion)currentNested.
getValue()));
311 retArray.add(suggestion.getNestedInSuggestion());
340 if(
AppBean.
getLockMaster().getSuggReqLock(requestInfo.getSession().getSyncDocument().getId()).lockForChange()){
346 if (allSuggest.isEmpty()) {
351 AppBean.getLockMaster().getSuggReqLock(
requestInfo.
getSession().getSyncDocument().getId()).unlockForChange();
363 ArrayList<Suggestion> oldSuggestions =
new ArrayList<Suggestion>();
364 ArrayList<Suggestion> addedSuggestions =
new ArrayList<Suggestion>();
365 ArrayList<Suggestion> changedSuggestions =
new ArrayList<Suggestion>();
366 ArrayList<AnnotType> newTypes =
new ArrayList<AnnotType>();
371 updateDocument(request,oldSuggestions,addedSuggestions,changedSuggestions, newTypes);
373 ArrayList<Suggestion> modifiedSuggestions =
new ArrayList<Suggestion>();
374 modifiedSuggestions.addAll(addedSuggestions);
375 modifiedSuggestions.addAll(changedSuggestions);
378 request.getSession().addMessageTS(result);
379 request.getSession().notifyComet();
381 synchronized(AppBean.getSessions()){
382 Iterator<EditorSession> sIt = AppBean.getSessions().iterator();
383 while (sIt.hasNext()) {
389 es.addMessageTS(result);
402 synchronized(AppBean.getSessions()){
403 Iterator<EditorSession> sesIt = AppBean.getSessions().iterator();
404 long sessionId = requestInfo.getSession().getSessionId();
405 while (sesIt.hasNext()) {
410 es.addMessageTS(message);
426 ArrayList<Suggestion> allSug = request.getSession().getWholeSendedSuggestions();
429 affectedSug.addAll(suggestionsToDelete);
432 requestInfo.getSession().addMessageTS(result);
433 requestInfo.getSession().notifyComet();
434 synchronized(AppBean.getSessions()){
435 Iterator<EditorSession> sIt = AppBean.getSessions().iterator();
436 while (sIt.hasNext()) {
442 es.addMessageTS(result);
457 boolean withAnc =
true;
461 String addedTStr =
"";
462 Iterator<AnnotType> typeIter = newTypes.iterator();
463 while (typeIter.hasNext()) {
468 addedTStr = addedTStr + type.toXMLString(withAnc);
470 addedTStr = addedTStr + type.toXMLStringV2(withAnc);
474 if (!addedTStr.isEmpty()) {
476 addedTStr =
"<types><add>" + addedTStr +
"</add></types>";
478 addedTStr =
"<addTypes>" + addedTStr +
"</addTypes>";
481 if (!addedTStr.isEmpty()) {
497 if (requestInfo.
getSession().getUser() == null) {
503 Iterator<UserGroup> grIter = requestInfo.getSession().getUser().getGroups().iterator();
504 while (grIter.hasNext()) {
524 ArrayList<Suggestion> shouldHave = null;
525 synchronized (session) {
527 ArrayList<Suggestion> filteredSuggest =
new ArrayList<Suggestion>(allSuggest);
533 modifiedSuggestions.addAll(removedSug);
534 checkTypes(session, shouldHave, newTypes,
true);
552 if(suggestion != null && linkedSuggestion != null){
554 List attrList = suggestion.getAttributes();
555 if(attrList != null && !attrList.isEmpty()){
558 Iterator attrIt = attrList.iterator();
559 while(attrIt.hasNext()){
561 Object actualAttr = (Object) attrIt.next();
566 SugLinkedAttribute actualLink= (SugLinkedAttribute) actualAttr;
586 ArrayList<SecApiReqTypeDef> availableTypes = null;
591 availableTypes = SECTypesTranslator.translate(SECAPIResults);
592 }
catch (Exception ex) {
593 String message =
"SEC API call error : " + ex.getMessage();
594 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, message);
595 AppBean.setReqTypeDefinitions(
new ArrayList<SecApiReqTypeDef>());
598 if (availableTypes == null || availableTypes.isEmpty()) {
599 AppBean.setReqTypeDefinitions(
new ArrayList<SecApiReqTypeDef>());
603 AppBean.setAvTypeDefinitions(availableTypes);
607 SecApiReqTypeDef.filterTypes();
617 ArrayList<SecApiReqTypeDef> availableTypes = null;
621 availableTypes = SECTypesTranslator.translate(SECAPIResults);
622 }
catch (Exception ex) {
623 String message =
"SEC API call error : " + ex.getMessage();
624 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, message);
625 AppBean.setReqTypeDefinitions(
new ArrayList<SecApiReqTypeDef>());
628 if (availableTypes == null || availableTypes.isEmpty()) {
629 AppBean.setReqTypeDefinitions(
new ArrayList<SecApiReqTypeDef>());
633 AppBean.setAvTypeDefinitions(availableTypes);
637 SecApiReqTypeDef.filterTypes();
643 @SuppressWarnings(
"unchecked")
645 String desiredJSONData =
"";
646 String unnecessaryJSONData =
"";
647 String unnecessaryAtJSONData =
"";
649 String desiredEAJSONData =
"";
650 String unnecessaryEAJSONData =
"";
651 String unnecessaryAtEAJSONData =
"";
653 Object[] paramsD = {
"name", Constants.SEC_DESIRED_TYPES_SETTINGS_NAME};
654 List<ServerSetting> settingsList = AppBean.getPersistenceManager().queryDB(
"ServerSetting.findByName", paramsD);
655 if (settingsList != null && !settingsList.isEmpty()) {
656 if (!settingsList.get(0).getSettingValue().isEmpty()) {
657 desiredJSONData = settingsList.get(0).getSettingValue();
660 Object[] paramsU = {
"name", Constants.SEC_UNNECESSARY_TYPES_SETTINGS_NAME};
661 settingsList = AppBean.getPersistenceManager().queryDB(
"ServerSetting.findByName", paramsU);
662 if (settingsList != null && !settingsList.isEmpty()) {
663 if (!settingsList.get(0).getSettingValue().isEmpty()) {
664 unnecessaryJSONData = settingsList.get(0).getSettingValue();
667 Object[] paramsUA = {
"name", Constants.SEC_UNNECESSARY_TYPES_SETTINGS_NAME};
668 settingsList = AppBean.getPersistenceManager().queryDB(
"ServerSetting.findByName", paramsUA);
669 if (settingsList != null && !settingsList.isEmpty()) {
670 if (!settingsList.get(0).getSettingValue().isEmpty()) {
671 unnecessaryAtJSONData = settingsList.get(0).getSettingValue();
675 Object[] paramsDEA = {
"name", Constants.SEC_DESIRED_TYPES_SETTINGS_NAME_EA};
676 settingsList = AppBean.getPersistenceManager().queryDB(
"ServerSetting.findByName", paramsDEA);
677 if (settingsList != null && !settingsList.isEmpty()) {
678 if (!settingsList.get(0).getSettingValue().isEmpty()) {
679 desiredEAJSONData = settingsList.get(0).getSettingValue();
682 Object[] paramsUEA = {
"name", Constants.SEC_UNNECESSARY_TYPES_SETTINGS_NAME_EA};
683 settingsList = AppBean.getPersistenceManager().queryDB(
"ServerSetting.findByName", paramsUEA);
684 if (settingsList != null && !settingsList.isEmpty()) {
685 if (!settingsList.get(0).getSettingValue().isEmpty()) {
686 unnecessaryEAJSONData = settingsList.get(0).getSettingValue();
689 Object[] paramsUAEA = {
"name", Constants.SEC_UNNECESSARY_TYPES_SETTINGS_NAME};
690 settingsList = AppBean.getPersistenceManager().queryDB(
"ServerSetting.findByName", paramsUAEA);
691 if (settingsList != null && !settingsList.isEmpty()) {
692 if (!settingsList.get(0).getSettingValue().isEmpty()) {
693 unnecessaryAtEAJSONData = settingsList.get(0).getSettingValue();
697 ArrayList<SecApiReqTypeDef> desiredTypes = SECTypesTranslator.translate(desiredJSONData);
698 ArrayList<SecApiReqTypeDef> unnecessaryTypes = SECTypesTranslator.translate(unnecessaryJSONData);
699 ArrayList<SecApiReqTypeDef> unnecessaryAttributes = SECTypesTranslator.translate(unnecessaryAtJSONData);
701 ArrayList<SecApiReqTypeDef> desiredTypesEA = SECTypesTranslator.translate(desiredEAJSONData);
702 ArrayList<SecApiReqTypeDef> unnecessaryTypesEA = SECTypesTranslator.translate(unnecessaryEAJSONData);
703 ArrayList<SecApiReqTypeDef> unnecessaryAttributesEA = SECTypesTranslator.translate(unnecessaryAtEAJSONData);
705 AppBean.setDesTypeDefinitions(desiredTypes);
706 AppBean.setUnTypeDefinitions(unnecessaryTypes);
707 AppBean.setUnAtDefinitions(unnecessaryAttributes);
709 AppBean.setDesTypeDefinitionsEA(desiredTypesEA);
710 AppBean.setUnTypeDefinitionsEA(unnecessaryTypesEA);
711 AppBean.setUnAtDefinitionsEA(unnecessaryAttributesEA);
725 String secApiXmlData = null;
727 String SECAPIResults =
"";
731 Boolean processed =
false;
734 SECAPIResults = sai.makeRequest(secApiRequest);
736 }
catch (Exception ex) {
737 String message =
"SEC API call error : " + ex.getMessage();
738 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, message);
742 if (SECAPIResults == null || SECAPIResults.isEmpty()) {
748 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE,
"Initialisation of SEC API failed!");
749 return secApiXmlData;
755 return secApiXmlData;
760 SECAPIResults = sai.makeRequest(secApiRequest);
762 }
catch (Exception ex) {
763 String message =
"SEC API call error : " + ex.getMessage();
764 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, message);
765 return secApiXmlData;
771 if (secApiXmlData.isEmpty()) {
774 return secApiXmlData;
788 String secApiXmlData = null;
790 String SECAPIResults =
"";
792 String secApiRequest =
"";
800 return secApiXmlData;
807 SECAPIResults = sac.sendReqToSECAPI(secApiRequest, parRequestInfo);
808 }
catch (Exception ex) {
809 String message =
"Remote SEC API call error : " + ex.getMessage();
810 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, message);
813 if(SECAPIResults == null){
819 if (secApiXmlData.isEmpty()) {
822 return secApiXmlData;
832 JSONObject jsonData = (JSONObject)JSONValue.parse(responseData);
833 if (jsonData == null) {
835 String msg =
"Unable to parse received JSON string with suggestions.";
836 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
843 String suggXML = null;
846 suggXML = (String) jsonData.get(
"annotation");
847 }
catch (Exception e) {
849 String msg =
"Unable to parse received JSON string with suggestions.";
850 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg, e);
865 String exceptionData = null;
867 exceptionData = (String) jsonData.get(
"exception");
868 }
catch (Exception e) {
870 if (exceptionData != null && !exceptionData.isEmpty()) {
872 String msg =
"SEC API returned exception: " + exceptionData;
873 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
889 StringBuilder reqTypes =
new StringBuilder();
890 ArrayList<SecApiReqTypeDef> rtdList = AppBean.getReqTypeDefinitions();
891 if (rtdList == null) {
893 String msg =
"Unable to get requseted type definitions while creating "
894 +
"SEC API Suggestions Request.";
895 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
897 rtdList =
new ArrayList<SecApiReqTypeDef>();
899 Iterator<SecApiReqTypeDef> rtdIt= rtdList.iterator();
900 if (rtdIt.hasNext()) {
902 reqTypes.append(rtd.getRequestString());
904 while (rtdIt.hasNext()) {
906 reqTypes.append(
", ");
907 reqTypes.append(rtd.getRequestString());
910 return "{ \"annotate\": {" +
912 " \"annotation_format\": [\"sxml\"]," +
913 " \"disambiguate\": " + (useAlternatives ?
"0" :
"1") +
"," +
914 " \"document_uri\": \"" + uri +
"\"," +
915 " \"types_and_attributes\": { " + reqTypes +
" }"+
926 return "{ \"get_entity_types_and_attributes\": {} }\n";
937 ArrayList<Integer> result =
new ArrayList<Integer>();
938 Iterator<String> sepIt = Constants.REFUSE_BORDER_SEPARATOR.iterator();
939 while (sepIt.hasNext()) {
940 String sep = sepIt.next();
941 int offset = doc.indexOf(sep);
942 while (offset >= 0) {
944 offset = doc.indexOf(sep, offset + 1);
947 Collections.sort(result);
961 ArrayList<SuggestionLogEntry> suggLog = request.getRefusedSuggestions();
962 ArrayList<Suggestion> changedSuggestions =
new ArrayList<Suggestion>();
963 Integer groupId = request.getSession().getDefaultGroup().getId();
965 ArrayList<SuggestionLogEntry> addToLog =
new ArrayList<SuggestionLogEntry>();
967 ArrayList<Suggestion> allSugg = request.getSession().getWholeSendedSuggestions();
968 if (allSugg != null && !allSugg.isEmpty()) {
969 HashMap<Integer, ArrayList<SuggestionFragment>> sugToLinFragments =
new HashMap<Integer, ArrayList<SuggestionFragment>>();
970 SECAPISuggestionTranslator.linearizeSuggestions(sugToLinFragments, request.getSession().getParsedSyncDocument(), allSugg);
972 int docLength = request.getSession().getParsedLinDocument().length();
974 Iterator<SuggestionLogEntry> refSugIt = suggLog.iterator();
975 while (refSugIt.hasNext()) {
977 if (skipSugs.contains(refSugLogEntry)) {
982 Integer refusedSuggestionId = Integer.parseInt(refSugLogEntry.getTmpId());
984 ArrayList<SuggestionFragment> suggFragList = refusedSuggestion.getFragmentsAL();
985 AnnotType refusedSuggType = refusedSuggestion.getAnnotType();
988 String refusedURI = refusedSuggestion.getSAEntityIdentifier();
989 if (refusedURI != null && !refusedURI.isEmpty()) {
990 if (suggFragList != null && !suggFragList.isEmpty()) {
991 if (suggFragList.size() >= 2) {
997 int rightSep = docLength;
998 Integer curOffset = null;
999 ArrayList<SuggestionFragment> frags = sugToLinFragments.get(refusedSuggestionId);
1001 if (frags != null && !frags.isEmpty()) {
1002 frag = frags.get(0);
1007 curOffset = frag.getOffset();
1008 Iterator<Integer> sepIt = separators.iterator();
1009 while (sepIt.hasNext()) {
1010 Integer s = sepIt.next();
1011 if (s < curOffset && leftSep < s) {
1014 if (s > curOffset && s < rightSep) {
1020 Iterator<Suggestion> allSuggIt = allSugg.iterator();
1021 while (allSuggIt.hasNext()) {
1025 frags = sugToLinFragments.get(actualSugg.getId());
1026 if (frags != null && !frags.isEmpty()) {
1027 frag = frags.get(0);
1032 curOffset = frag.getOffset();
1038 Integer actualSuggId = actualSugg.getId();
1039 AnnotType actualSuggType = actualSugg.getAnnotType();
1040 String actualURI = actualSugg.getSAEntityIdentifier();
1041 if (actualSuggId != null && refusedSuggestionId != null && !actualSuggId.equals(refusedSuggestionId)
1042 && actualSuggType != null && refusedSuggType != null && actualSuggType.equals(refusedSuggType)
1043 && actualURI != null && refusedURI.equals(actualURI)) {
1045 ArrayList<SuggestionFragment> tmpFragList = actualSugg.getFragmentsAL();
1046 if (tmpFragList.size() >= 2) {
1050 if (tmpFragList.size() == suggFragList.size()) {
1051 Iterator<SuggestionFragment> tmpFragListIt = tmpFragList.iterator();
1052 Iterator<SuggestionFragment> suggFragListIt = suggFragList.iterator();
1053 Boolean errFlag =
false;
1055 while (tmpFragListIt.hasNext()) {
1064 String path1 = tmpFrag1.getPath();
1065 String path2 = tmpFrag2.getPath();
1066 if (path1 != null && path2 != null && path1.equals(path2)) {
1067 Integer offset1 = tmpFrag1.getOffset();
1068 Integer offset2 = tmpFrag2.getOffset();
1069 if (offset1 != null && offset2 != null && offset1.equals(offset2)) {
1075 if (curOffset != null) {
1076 if (curOffset < leftSep || curOffset > rightSep) {
1083 addToLog.add(tmpLogEntry);
1093 suggLog.addAll(addToLog);
1095 if(suggLog != null && !suggLog.isEmpty()){
1096 Iterator<SuggestionLogEntry> logIt = suggLog.iterator();
1097 while(logIt.hasNext()){
1100 boolean createAlternatives =
true;
1101 if (noAlternatives.contains(actualLogItem)) {
1102 createAlternatives =
false;
1109 return changedSuggestions;
1119 ArrayList<SuggestionLogEntry> addToLog =
new ArrayList<SuggestionLogEntry>();
1120 ArrayList<SuggestionLogEntry> confSugs = request.getConfirmedSuggestions();
1122 ArrayList<Suggestion> allSugg = request.getSession().getWholeSendedSuggestions();
1123 if (allSugg != null && !allSugg.isEmpty()) {
1124 HashMap<Integer, ArrayList<SuggestionFragment>> sugToLinFragments =
new HashMap<Integer, ArrayList<SuggestionFragment>>();
1125 SECAPISuggestionTranslator.linearizeSuggestions(sugToLinFragments, request.getSession().getParsedSyncDocument(), allSugg);
1127 int docLength = request.getSession().getParsedLinDocument().length();
1129 Iterator<SuggestionLogEntry> confSugIt = confSugs.iterator();
1130 while (confSugIt.hasNext()) {
1134 Integer confirmedSuggestionId = Integer.parseInt(confSugLogEntry.getTmpId());
1136 ArrayList<SuggestionFragment> suggFragList = confirmedSuggestion.getFragmentsAL();
1138 if (suggFragList != null && !suggFragList.isEmpty()) {
1139 if (suggFragList.size() >= 2) {
1143 Iterator<Suggestion> allSuggIt = allSugg.iterator();
1144 while (allSuggIt.hasNext()) {
1148 Integer actualSuggId = actualSugg.getId();
1149 if (actualSuggId != null && confirmedSuggestionId != null && !actualSuggId.equals(confirmedSuggestionId)) {
1151 ArrayList<SuggestionFragment> tmpFragList = actualSugg.getFragmentsAL();
1152 if (tmpFragList.size() >= 2) {
1156 if (tmpFragList.size() == suggFragList.size()) {
1157 Iterator<SuggestionFragment> tmpFragListIt = tmpFragList.iterator();
1158 Iterator<SuggestionFragment> suggFragListIt = suggFragList.iterator();
1159 Boolean errFlag =
false;
1161 while (tmpFragListIt.hasNext()) {
1170 String path1 = tmpFrag1.getPath();
1171 String path2 = tmpFrag2.getPath();
1172 if (path1 != null && path2 != null && !path1.equals(path2)) {
1177 Integer offset1 = tmpFrag1.getOffset();
1178 Integer offset2 = tmpFrag2.getOffset();
1179 if (offset1 != null && offset2 != null && !offset1.equals(offset2)) {
1187 addToLog.add(tmpLogEntry);
1196 request.getRefusedSuggestions().addAll(addToLog);
1233 if(feedback != null){
1234 feedback.setAnnot(null);
1235 feedback.setAnnotationId(null);
1237 Suggestion sug4update = feedback.getSuggestion();
1238 Iterator<SugBaseAttribute> attrIt = sug4update.getAttributes().iterator();
1239 while(attrIt.hasNext()){
1243 attr.setNestedSuggestion(updatedSugg);
1246 AppBean.getPersistenceManager().saveEntityChanges(sug4update);
1251 if(actualSuggestion != null){
1253 feedback.setAnnot(null);
1254 feedback.setAnnotationId(null);
1255 feedback.setGroup(request.getSession().getDefaultGroup());
1256 feedback.setGroupId(request.getSession().getDefaultGroup().getId());
1257 feedback.setSuggestion(actualSuggestion);
1258 feedback.setSuggestionId(actualSuggestion.getId());
1260 Iterator<SugBaseAttribute> attrIt = actualSuggestion.getAttributes().iterator();
1261 while(attrIt.hasNext()){
1265 attr.setNestedSuggestion(updatedSugg);
1268 AppBean.getPersistenceManager().saveEntityChanges(actualSuggestion);
1270 if (processAlternatives) {
1271 AlternativeManager.activateAlternatives(request, actualSuggestion);
1273 return actualSuggestion;
1292 private void updateDocument(
RequestInfo request, ArrayList<Suggestion> oldSuggestions, ArrayList<Suggestion> addedSuggestions, ArrayList<Suggestion> changedSuggestions, ArrayList<AnnotType> newTypes){
1293 userGroup = requestInfo.getSession().getDefaultGroup();
1297 String rawNewSuggestions = null;
1298 ArrayList<Suggestion> newSuggestions = null;
1299 String document = request.getSession().getParsedLinDocument();
1300 String uri = request.getSession().getSyncDocument().getUri();
1313 if (rawNewSuggestions == null) {
1325 newSuggestions = st.translateSugFromSecApi(request, rawNewSuggestions, newTypes);
1328 if(newSuggestions != null && !newSuggestions.isEmpty()){
1335 SugPersister.persist(request, null, null, changedSuggestions,
false, newTypes);
1338 oldSuggestions.clear();
1342 checkTypes(request.getSession(), oldSuggestions, newTypes,
false);
1343 checkTypes(request.getSession(), changedSuggestions, newTypes,
true);
1350 SugPersister.persist(request, null, null, addedSuggestions,
false, newTypes);
1352 SugPersister.persist(request, null, null, changedSuggestions,
false, newTypes);
1357 alternativesThread.start();
1359 }
catch(Exception ex){
1360 String msg =
"Unknown exception in SuggestionManager: " + ex.getMessage();
1361 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg, ex);
1375 if (document != null && !document.isEmpty()) {
1380 return suggestionSource;
1390 StringBuilder result =
new StringBuilder();
1391 if(suggestions != null && !suggestions.isEmpty()){
1392 ArrayList<String> attFilter = requestInfo.getSession().getAttFilter();
1393 Boolean KBRefMode = requestInfo.getSession().getKBRefMode();
1394 int lNum = requestInfo.getSession().getLanguageNum();
1395 Iterator<Suggestion> suggIt = suggestions.iterator();
1396 while(suggIt.hasNext()){
1399 result.append(actualSugg.toXMLStringV2(attFilter, lNum, KBRefMode));
1401 Integer
id = actualSugg.getId();
1402 String params =
" tmpId=\"" + ((
id == null) ?
"null" :
id.toString()) +
"\" confidence=\"" + actualSugg.
getConfidence().toString() +
"\"";
1403 result.append(actualSugg.toXMLString(
true, params,
false));
1408 return result.toString();
1419 int result = s1.getConfidence().compareTo(s2.
getConfidence());
1423 return (result * (-1));
1435 StringBuilder result =
new StringBuilder();
1436 if(suggestions != null && !suggestions.isEmpty() && requestInfo.getSession().getProtocolLOD() <
Constants.PROTOCOL_LOD_V2){
1437 Iterator<Integer> suggIt = suggestions.iterator();
1438 while(suggIt.hasNext()){
1439 result.append(
"<delete tmpId=\"");
1440 result.append(suggIt.next().toString());
1441 result.append(
"\"/>");
1443 }
else if (suggestions != null && !suggestions.isEmpty()) {
1444 ArrayList<Integer> skipSug =
new ArrayList<Integer>();
1446 Iterator<SuggestionLogEntry> sleIt = requestInfo.getOrigRefusedSuggestions().iterator();
1447 while (sleIt.hasNext()) {
1451 sid = Integer.parseInt(sle.getTmpId());
1452 }
catch (NumberFormatException numberFormatException) {
1459 Iterator<SuggestionLogEntry> sleIt = requestInfo.getConfirmedSuggestions().iterator();
1460 while (sleIt.hasNext()) {
1464 sid = Integer.parseInt(sle.getTmpId());
1465 }
catch (NumberFormatException numberFormatException) {
1471 Iterator<Integer> suggIt = suggestions.iterator();
1472 while(suggIt.hasNext()){
1473 Integer sugId = suggIt.next();
1474 if (skipSug.contains(sugId)) {
1477 result.append(
"<suggestion uri=\"");
1478 result.append(AppBean.getBaseUri());
1479 result.append(
"/sugg/");
1480 result.append(sugId.toString());
1481 result.append(
"\"/>");
1485 return result.toString();
1496 StringBuilder result =
new StringBuilder();
1497 if(!suggestionToAddM.isEmpty() || !suggestionToRemoveM.isEmpty()){
1500 result.append(
"<removeSuggestions>");
1501 result.append(suggestionToRemoveM);
1502 result.append(
"</removeSuggestions>");
1503 result.append(
"<addSuggestions>");
1504 result.append(suggestionToAddM);
1505 result.append(
"</addSuggestions>");
1507 result.append(
"<suggestions>");
1508 result.append(suggestionToRemoveM);
1509 result.append(suggestionToAddM);
1510 result.append(
"</suggestions>");
1514 result.append(
"<addSuggestions/>");
1516 return result.toString();
1519 private void getNewClientCache(ArrayList<Suggestion> addedSugg, ArrayList<Integer> deletedSugg, ArrayList<Integer> actualCache){
1521 if(deletedSugg != null && !deletedSugg.isEmpty()){
1522 Iterator<Integer> deletedIt = deletedSugg.iterator();
1523 while(deletedIt.hasNext()){
1524 Integer actualForDelete = deletedIt.next();
1525 if(actualCache.contains(actualForDelete)){
1526 actualCache.remove(actualForDelete);
1532 if(addedSugg != null && !addedSugg.isEmpty()){
1533 Iterator<Suggestion> addedIt = addedSugg.iterator();
1534 while(addedIt.hasNext()){
1536 if(!actualCache.contains(actualForAdd.
getId())){
1537 actualCache.add(actualForAdd.getId());
1554 ArrayList<Suggestion> sugToAdd =
new ArrayList<Suggestion>();
1555 ArrayList<Integer> sugToDelete =
new ArrayList<Integer>();
1557 synchronized (session) {
1559 ArrayList<Integer> clientCacheID = session.getSendedSuggestions();
1560 ArrayList<Suggestion> clientCache =
new ArrayList<Suggestion>();
1561 for (Iterator<Integer> it = clientCacheID.iterator(); it.hasNext();) {
1562 Integer
id = it.next();
1566 ArrayList<Suggestion> helpList =
new ArrayList<Suggestion>();
1567 helpList.addAll(clientCache);
1568 for (Iterator<Suggestion> it = helpList.iterator(); it.hasNext();) {
1570 if ((!shouldHave.contains(sg)) || changedSuggestions.contains(sg)) {
1571 if (!sugToDelete.contains(sg.
getId())) {
1572 sugToDelete.add(sg.getId());
1574 clientCache.remove(sg);
1578 for (Iterator<Suggestion> it = shouldHave.iterator(); it.hasNext();) {
1580 if (!clientCache.contains(sg)) {
1581 clientCache.add(sg);
1582 if (!sugToAdd.contains(sg)) {
1588 ArrayList<Suggestion> closed =
new ArrayList<Suggestion>(sugToAdd);
1589 ArrayList<Suggestion> visited =
new ArrayList<Suggestion>();
1590 while (!closed.isEmpty()) {
1592 visited.add(actualSugg);
1595 while (linkedSuggIt.hasNext()) {
1596 Suggestion actualLinkedSugg = linkedSuggIt.next();
1597 if (clientCache.contains(actualLinkedSugg)) {
1598 if (!sugToDelete.contains(actualLinkedSugg.
getId())) {
1599 sugToDelete.add(actualLinkedSugg.getId());
1601 if (!sugToAdd.contains(actualLinkedSugg)) {
1602 sugToAdd.add(actualLinkedSugg);
1604 if (!visited.contains(actualLinkedSugg)) {
1605 closed.add(actualLinkedSugg);
1612 session.setSendedSugg(clientCacheID);
1614 for (Iterator<Suggestion> sugIt = sugToAdd.iterator(); sugIt.hasNext();) {
1616 if (suggestion.
getNestedInAnnot() != null || suggestion.getNestedInSuggestion() != null) {
1624 return clientMessage;
1637 Integer documentId = request.getSession().getSyncDocument().getId();
1638 Integer userGroupId = request.getSession().getDefaultGroup().getId();
1639 ArrayList<Suggestion> result =
new ArrayList<Suggestion>();
1643 if(negFeedback != null && !negFeedback.isEmpty() && docSuggestions != null && !docSuggestions.isEmpty()){
1646 Iterator<Suggestion> docSugIt = docSuggestions.iterator();
1647 while(docSugIt.hasNext()){
1648 Suggestion actualSuggestion = docSugIt.next();
1649 Iterator<SuggestionFeedback> negFeedbackIt = negFeedback.iterator();
1650 while(negFeedbackIt.hasNext()){
1652 if(actualSuggestion.
getId().equals(negFeedbackIt.next().getSuggestionId())){
1654 result.add(actualSuggestion);
1673 if (suggestionId == null || list == null) {
1676 for (Iterator<Suggestion> it = list.iterator(); it.hasNext();) {
1678 if (sg.
getId() == null) {
1681 if (sg.
getId().equals(suggestionId)) {
1697 ArrayList<Suggestion> removedSuggestions =
new ArrayList<Suggestion>();
1698 UserGroup defGroup = requestInfo.getSession().getDefaultGroup();
1699 Integer defaultUserGroupID = null;
1700 if (defGroup != null) {
1701 defaultUserGroupID = defGroup.getId();
1704 defaultUserGroupID = this.userGroup.getId();
1707 removedSuggestions.addAll(list);
1708 list.removeAll(list);
1709 return removedSuggestions;
1714 ArrayList<SuggestionFeedback> feedListOtherGroups =
new ArrayList<SuggestionFeedback>();
1717 Iterator<UserGroup> allUserGroups = requestInfo.getSession().getUser().getGroupsAL().iterator();
1718 while(allUserGroups.hasNext()){
1720 if(group.
getId() != defaultUserGroupID){
1722 feedListOtherGroups.addAll(feed);
1728 for (Iterator<SuggestionFeedback> it = feedList.iterator(); it.hasNext();) {
1734 if (sgFromList != null) {
1740 for (Iterator<SuggestionFeedback> it = feedListOtherGroups.iterator(); it.hasNext();) {
1746 if (sgFromList != null) {
1751 return removedSuggestions;
1767 ArrayList<Suggestion> removedSuggestions)
1769 for (Iterator<Suggestion> itList = list.iterator(); itList.hasNext(); ) {
1771 List atrs = sg.getAttributes();
1773 for (Iterator it2 = atrs.iterator(); it2.hasNext();) {
1774 Object obj = (Object) it2.next();
1775 Object value = null;
1777 value = ((SugLinkedAttribute) obj).getValue();
1780 value = ((SugNestedAttribute) obj).getValue();
1783 if (((Suggestion) value).equals(sgFromList)) {
1784 if (obj instanceof SugLinkedAttribute) {
1785 ((SugLinkedAttribute) obj).setValue(fb.getAnnot());
1786 if (modified != null && !modified.contains(sg)) {
1790 if (obj instanceof SugNestedAttribute) {
1791 ((SugNestedAttribute) obj).setValue(fb.getAnnot());
1792 if (modified != null && !modified.contains(sg)) {
1800 list.remove(sgFromList);
1801 removedSuggestions.add(sgFromList);
1812 if(feedbackList != null){
1813 Iterator<SuggestionFeedback> feedbackgIterator = feedbackList.iterator();
1814 while(feedbackgIterator.hasNext()){
1816 if(actualFeedback.
getAnnot() != null && actualFeedback.getSuggestionId().equals(searchedSugg.
getId())){
1834 ArrayList<Suggestion> toRet =
new ArrayList<Suggestion>();
1835 if (!inputSuggs.isEmpty()) {
1836 Iterator<Suggestion> inputSuggsIt = inputSuggs.iterator();
1838 while (inputSuggsIt.hasNext()) {
1843 Integer nestedIn = null;
1845 nestedIn = inputSug.getNestedInSuggestion().getId();
1847 Iterator<Suggestion> suggsToDeleteIt = suggsToDelete.iterator();
1849 while (suggsToDeleteIt.hasNext()) {
1850 Suggestion suggToDelete = suggsToDeleteIt.next();
1852 if (suggToDelete.
getId() != null && nestedIn != null && suggToDelete.getId() == nestedIn) {
1854 toRet.add(inputSug);
1856 inputSuggsIt.remove();
1873 private ArrayList<Suggestion>
cutRefusedSuggLinks(ArrayList<Suggestion> userSuggestions, ArrayList<Suggestion> refusedSuggestions){
1874 ArrayList<Suggestion> changedSuggestions =
new ArrayList<Suggestion>();
1875 if(userSuggestions != null && !userSuggestions.isEmpty() && refusedSuggestions != null && !refusedSuggestions.isEmpty()){
1876 Iterator<Suggestion> userSuggIt = userSuggestions.iterator();
1877 while(userSuggIt.hasNext()){
1879 List attrList = actualSugg.getAttributes();
1880 Iterator attrListIt = attrList.iterator();
1882 while(attrListIt.hasNext()){
1883 Object actualObject = (Object) attrListIt.next();
1886 SugLinkedAttribute actualLink = (SugLinkedAttribute)actualObject;
1888 Iterator<Suggestion> refSugIterator = refusedSuggestions.iterator();
1889 while(refSugIterator.hasNext()){
1891 if(((Suggestion)actualLink.
getValue()).getId().equals(refSugIterator.next().getId())){
1893 actualLink.setValue(null);
1894 if(!changedSuggestions.contains(actualSugg)){
1895 changedSuggestions.add(actualSugg);
1902 SugNestedAttribute actualLink = (SugNestedAttribute)actualObject;
1904 Iterator<Suggestion> refSugIterator = refusedSuggestions.iterator();
1905 while(refSugIterator.hasNext()){
1907 if(((Suggestion)actualLink.
getValue()).getId().equals(refSugIterator.next().getId())){
1909 actualLink.setValue(null);
1910 if(!changedSuggestions.contains(actualSugg)){
1911 changedSuggestions.add(actualSugg);
1920 return changedSuggestions;
1931 if(requestInfo != null && requestInfo.
getSession().getMinConfidence() != null && requestInfo.
getSession().getMinConfidence() != 0)
1946 if(userSuggestions != null && !userSuggestions.isEmpty()){
1947 Iterator<Suggestion> suggIt = userSuggestions.iterator();
1948 while(suggIt.hasNext()){
1950 if(actualSuggeston.
getConfidence().compareTo(minimalConfidence) < 0){
1966 public static ArrayList<Suggestion>
addAllDependencies(ArrayList<Suggestion> filteredSuggestions, ArrayList<Suggestion> nonFilteredSuggestion) {
1967 ArrayList<Suggestion> open =
new ArrayList<Suggestion>(nonFilteredSuggestion);
1968 ArrayList<Suggestion> closed =
new ArrayList<Suggestion>(filteredSuggestions);
1969 ArrayList<Suggestion> result =
new ArrayList<Suggestion>(filteredSuggestions);
1970 open.removeAll(result);
1972 while(!closed.isEmpty()) {
1977 while(linkedSuggIt.hasNext()){
1978 Suggestion actualLinkedSugg = linkedSuggIt.next();
1979 if(open.contains(actualLinkedSugg)){
1980 open.remove(actualLinkedSugg);
1981 closed.add(actualLinkedSugg);
1982 result.add(actualLinkedSugg);
1998 if(!pairs.isEmpty()){
1999 Iterator<AnnotSugPair> pairsIt = pairs.iterator();
2000 while(pairsIt.hasNext()){
2021 String namesStr = uri.replace(AppBean.getBaseTypeUri(),
"");
2022 int index = namesStr.indexOf(
'/');
2023 String withoutGroup = namesStr.substring(index);
2024 String result = AppBean.getBaseTypeUri() +
"g" + groupId.toString() + withoutGroup;
2036 if (list != null && !list.isEmpty()) {
2037 Iterator<AnnotType> newTypesIt = list.iterator();
2038 while (newTypesIt.hasNext()) {
2041 if (newType.
getUri().equals(uri)) {
2058 public static void checkTypes(
EditorSession session, ArrayList<Suggestion> suggestions, ArrayList<AnnotType> newTypes,
boolean solveAtribute){
2059 boolean someTypesWasCloned =
false;
2060 if(suggestions != null && !suggestions.isEmpty()){
2061 Iterator<Suggestion> suggIt = suggestions.iterator();
2064 while(suggIt.hasNext()){
2066 AnnotType actualType = actualSuggestion.getAnnotType();
2067 String changedUri =
changeGroupInUri(actualType.getUri(),session.getDefaultGroup().getId());
2071 if (typeFromList != null) {
2072 actualSuggestion.setAnnotType(typeFromList);
2075 if(typeFromDB == null){
2079 actualSuggestion.setAnnotType(newType);
2080 someTypesWasCloned =
true;
2083 actualSuggestion.setAnnotType(typeFromDB);
2089 if (solveAtribute && someTypesWasCloned) {
2091 List<AnnotType> wasProcessed =
new ArrayList<AnnotType>();
2094 newTypesCount = newTypes.size();
2095 ArrayList<AnnotType> currentProcessedTypes =
new ArrayList<AnnotType>(newTypes);
2096 for (Iterator<AnnotType> itType = currentProcessedTypes.iterator(); itType.hasNext();) {
2101 for (Iterator<AnnotTypeAttr> itAttr = type.
getAttributes().iterator(); itAttr.hasNext();) {
2103 AnnotType atrType = atr.getAttributeType();
2104 if (atrType != null) {
2105 String changedUri =
changeGroupInUri(atrType.getUri(),session.getDefaultGroup().getId());
2110 if(typeFromDB == null){
2116 wasProcessed.add(type);
2118 }
while (newTypesCount != newTypes.size());
2120 for (Iterator<AnnotType> itType = newTypes.iterator(); itType.hasNext();) {
2122 for (Iterator<AnnotTypeAttr> itAttr = type.
getAttributes().iterator(); itAttr.hasNext();) {
2124 AnnotType atrType = atr.getAttributeType();
2125 if (atrType != null) {
2126 String changedUri =
changeGroupInUri(atrType.getUri(),session.getDefaultGroup().getId());
2129 if (clonedType == null) {
2132 if(typeFromDB != null){
2133 atr.setAttributeType(typeFromDB);
2136 String msg =
"Cloning of type " + changedUri +
" was unsuccessful.";
2137 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
2141 atr.setAttributeType(clonedType);
2160 ArrayList<Suggestion> changedSuggestions =
new ArrayList<Suggestion>();
2161 if(removedAnnot != null && !removedAnnot.isEmpty()){
2162 Iterator<Annotation> annotIt = removedAnnot.iterator();
2163 while(annotIt.hasNext()){
2166 if(foundedFeedback != null){
2169 Iterator<SugLinkedAttribute> attrIt = attrList.iterator();
2170 while(attrIt.hasNext()){
2176 Iterator<SugNestedAttribute> nAttrIt = nAttrsList.iterator();
2177 while(nAttrIt.hasNext()){
2182 foundedFeedback.setAnnot(null);
2186 String msg =
"Annotation without feedback found.";
2187 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
2192 return changedSuggestions;
2204 private void compareFragments(ArrayList<Suggestion> suggestions, ArrayList<Suggestion> changedSuggestions) {
2205 ArrayList<Suggestion> processedSuggestions =
new ArrayList<Suggestion>();
2206 for (Iterator<Suggestion> it = suggestions.iterator(); it.hasNext();) {
2209 if (processedSuggestions.contains(sg)) {
2217 ArrayList<Suggestion> sameSuggestion =
findSuggestions(suggestions, sg);
2218 if (sameSuggestion.size() <= 1) {
2222 boolean oneCorrect =
false;
2223 for (Iterator<Suggestion> itSame = sameSuggestion.iterator(); itSame.hasNext();) {
2225 processedSuggestions.add(someSuggestion);
2243 sg.setConfidence(confidence);
2244 changedSuggestions.add(sg);
2245 List atrList = sg.getAttributes();
2246 if (atrList == null) {
2249 for (Iterator itAtr = atrList.iterator(); itAtr.hasNext();) {
2250 Object obj = itAtr.next();
2254 SugNestedAttribute atr = (SugNestedAttribute) obj;
2271 if(suggestions != null && !suggestions.isEmpty()){
2274 Iterator<Suggestion> suggIt = suggestions.iterator();
2275 while(suggIt.hasNext()){
2285 Iterator<SuggestionFragment> fragIt = actualSuggestion.getFragments().iterator();
2286 while(fragIt.hasNext()){
2295 changedSugg.add(actualSuggestion);
2319 private void insertNewSuggestions(ArrayList<Suggestion> newSuggestions, ArrayList<Suggestion> oldSuggestions, ArrayList<Suggestion> addedSugg, ArrayList<Suggestion> changedSugg){
2320 if(newSuggestions != null && !newSuggestions.isEmpty() && oldSuggestions != null){
2322 if(!oldSuggestions.isEmpty()){
2324 Iterator<Suggestion> newSugIt = newSuggestions.iterator();
2325 while(newSugIt.hasNext()){
2326 Suggestion actualNewSuggestion = newSugIt.next();
2330 if(findedSugg != null){
2334 if (!finded.
contentEquals(actualNewSuggestion,
false,
true)) {
2337 addedSugg.add(actualNewSuggestion);
2346 addedSugg.add(actualNewSuggestion);
2367 Iterator<Suggestion> newSugIt = newSuggestions.iterator();
2368 while(newSugIt.hasNext()){
2374 addedSugg.addAll(newSuggestions);
2386 if(list != null && !list.isEmpty()){
2387 Iterator<Suggestion> listIt = list.iterator();
2388 while(listIt.hasNext()){
2390 if(actualSuggestion.
getId() != null && actualSuggestion.getId().equals(
id)){
2391 return actualSuggestion;
2438 Document parsedDoc = request.getSession().getParsedSyncDocument();
2439 if (parsedDoc == null) {
2446 int nowOrphFragCnt = 0;
2447 int updatedFragCnt = 0;
2448 Iterator<SuggestionFragment> fragIt = suggestion.getFragments().iterator();
2449 while (fragIt.hasNext()) {
2453 UpdatableFragment uf = exactMatcherProvider.match(parsedDoc, fragment.toUpdatableFragment());
2456 fragment.setIsGood(
true);
2462 ArrayList<UpdatableFragment> ufl =
new ArrayList<UpdatableFragment>();
2464 UpdatableFragment ufTemp = nearestMatcherProvider.matchInClosestNode(parsedDoc, fragment.toUpdatableFragment());
2465 if (ufTemp != null) {
2469 ufl = sequenceMatcherProvider.matchAllIncrementally(parsedDoc, fragment.toUpdatableFragment());
2471 if (ufl.size() == 1) {
2473 Iterator<UpdatableFragment> ufIt = ufl.iterator();
2475 fragment.updateWithUpdatableFragment(uf);
2478 fragment.setIsGood(
true);
2480 }
else if (ufl.isEmpty()) {
2482 fragment.setIsGood(
false);
2488 int minBadness = Integer.MAX_VALUE;
2490 String origPath = fragment.getPath();
2491 String origText = fragment.getAnnotatedText();
2492 int origOffset = fragment.getOffset();
2493 for (Iterator<UpdatableFragment> uflIt = ufl.iterator(); uflIt.hasNext();) {
2495 int lD = Util.levenshtein(origPath, ufr.getXPathString());
2496 int lDT = Util.levenshtein(origText, ufr.getText());
2497 int offDistance = Math.abs(origOffset - ufr.getOffset());
2498 int badness = 10000 * lD + 1000 * lDT + offDistance;
2499 if (badness < minBadness) {
2500 minBadness = badness;
2505 fragment.updateWithUpdatableFragment(uf);
2508 fragment.setIsGood(
true);
2512 }
catch (XPathExpressionException ex) {
2514 fragment.setIsGood(
false);
2518 }
catch (Exception e) {
2520 String msg =
"Update of suugestion fragments failed.";
2521 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg, e);
2528 if (badFragCnt == suggestion.
getFragments().size() && nowOrphFragCnt > 0) {
2530 }
else if (nowOrphFragCnt > 0) {
2533 if (nowOrphFragCnt > 0 || updatedFragCnt > 0) {
2548 Iterator<Suggestion> newSugIt = suggestions.iterator();
2549 while(newSugIt.hasNext()){
2568 ArrayList<Suggestion> findedSuggestions =
new ArrayList<Suggestion>();
2569 Iterator<Suggestion> newSugIt = suggestions.iterator();
2570 while(newSugIt.hasNext()){
2573 findedSuggestions.add(actualSugg);
2577 return findedSuggestions;
2588 ArrayList<SuggestionFragment> result =
new ArrayList<SuggestionFragment>();
2589 if(fragments != null && !fragments.isEmpty()){
2591 Iterator<Fragment> fragIt = fragments.iterator();
2592 while(fragIt.hasNext()){
2593 Fragment currentFragment = fragIt.next();
2596 newFragment.setAnnotatedText(currentFragment.getAnnotatedText());
2597 newFragment.setIsGood(currentFragment.getIsGood());
2598 newFragment.setLength(currentFragment.getLength());
2599 newFragment.setOffset(currentFragment.getOffset());
2600 newFragment.setPath(currentFragment.getPath());
2601 newFragment.setRefSuggestion(reference);
2602 result.add(newFragment);
2616 if(userSuggestions != null && !userSuggestions.isEmpty()
2617 && session.getSuggestionsFr() != null
2620 Document doc = session.getParsedSyncDocument();
2622 Integer offset = session.getSuggestionsFr().
get(0).getOffset();
2623 Integer length = session.getSuggestionsFr().
get(0).getLength();
2626 if(length != null && length == 0) {
2627 session.getSuggestionsFr().clear();
2628 userSuggestions.clear();
2632 else if (offset == null && length == null) {
2636 if(linFragments != null && !linFragments.isEmpty()){
2639 Iterator<Suggestion> suggIterator = userSuggestions.iterator();
2640 while(suggIterator.hasNext()){
2641 Suggestion actualSuggestion = suggIterator.next();
2644 Iterator<SuggestionFragment> linFragIt = linFragments.iterator();
2646 while(linFragIt.hasNext()){
2647 if(!
isInFragment(doc,actualSuggestion,linFragIt.next())){
2648 suggIterator.remove();
2655 session.getSuggestionsFr().clear();
2657 }
else if(userSuggestions != null && !userSuggestions.isEmpty()){
2658 userSuggestions.clear();
2669 if(userSuggestions != null && !userSuggestions.isEmpty()){
2671 ArrayList<String> requestedTypeUris = session.getSuggestionsTypes();
2672 if(requestedTypeUris != null && !requestedTypeUris.isEmpty()){
2673 if (!(requestedTypeUris.size() == 1 && requestedTypeUris.get(0) == null)) {
2675 Iterator<Suggestion> suggIterator = userSuggestions.iterator();
2676 while (suggIterator.hasNext()) {
2677 boolean fits =
false;
2685 Suggestion actualSuggestion = suggIterator.next();
2686 String actualUri = actualSuggestion.getAnnotType().getUri();
2689 actualUri = actualUri.replace(AppBean.getBaseTypeUri(),
"");
2690 actualUri = actualUri.substring(actualUri.indexOf(
"/")+1);
2692 Iterator<String> urisIterator = requestedTypeUris.iterator();
2693 while (urisIterator.hasNext()) {
2694 String suggType = urisIterator.next();
2696 suggType = suggType.replace(AppBean.getBaseTypeUri(),
"");
2697 suggType= suggType.substring(suggType.indexOf(
"/")+1);
2699 if ((actualUri.startsWith(suggType) && actualUri.length() > suggType.length() && actualUri.charAt(suggType.length()) ==
'/')
2700 || actualUri.equals(suggType)) {
2708 suggIterator.remove();
2723 public static ArrayList<SuggestionFragment>
getLinearized(Document doc, ArrayList<SuggestionFragment> fragments){
2724 ArrayList<ArrayList<SuggestionFragment>> notConverted =
new ArrayList<ArrayList<SuggestionFragment>>();
2725 ArrayList<ArrayList<SuggestionFragment>> comFragments =
new ArrayList<ArrayList<SuggestionFragment>>();
2727 comFragments.add(fragments);
2729 ArrayList<SuggestionFragment> linearizedList;
2730 linearizedList = Linearizer.fragmentsToLinSugFragments(comFragments,doc, notConverted,
true);
2732 if (!notConverted.isEmpty()) {
2734 Iterator<ArrayList<SuggestionFragment>> notCIT = notConverted.iterator();
2735 while (notCIT.hasNext()) {
2736 ArrayList<SuggestionFragment> notC = notCIT.next();
2738 if (!notC.isEmpty()) {
2740 String msg =
"Some fragments was not linearized successfully.";
2741 Logger.getLogger(SuggestionManager.class.getName()).log(Level.WARNING, msg);
2747 return linearizedList;
2758 Iterator<SuggestionFragment> linSuggFragmentsIt;
2766 }
catch(RuntimeException ex){
2768 String msg = ex +
"Can't convert fragments of suggestion: " + sugg.toString();
2769 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
2776 int fragStart = linFragment.getOffset().intValue();
2777 int fragEnd = fragStart + linFragment.getLength().intValue();
2779 while(linSuggFragmentsIt.hasNext()){
2783 int sugFragStart = actualSuggFragment.getOffset().intValue();
2784 int sugFragEnd = sugFragStart + actualSuggFragment.getLength().intValue();
2786 if(fragStart <= sugFragStart && fragEnd >= sugFragStart){
2789 }
else if(fragStart <= sugFragEnd && fragEnd >= sugFragEnd){
2804 ArrayList<Suggestion> retArray =
new ArrayList<Suggestion>();
2805 if(suggestion != null){
2808 List attrObjects = suggestion.getAttributes();
2809 if(attrObjects != null && !attrObjects.isEmpty()){
2810 Iterator attrIt = attrObjects.iterator();
2811 while(attrIt.hasNext()){
2812 Object actualObject = (Object) attrIt.next();
2817 SugLinkedAttribute currentLink = (SugLinkedAttribute)actualObject;
2820 retArray.add(((Suggestion)currentLink.
getValue()));
2838 newType.setComment(referenceType.getComment());
2839 newType.setGroup(null);
2840 newType.setName(referenceType.getName());
2841 newType.setRestrictedAtt(referenceType.getRestrictedAtt());
2842 newType.setUriInOntology(referenceType.getUriInOntology());
2853 ArrayList<AnnotTypeAttr> clonedAttr =
new ArrayList<AnnotTypeAttr>();
2856 Iterator<AnnotTypeAttr> attrIt = referenceType.getAttributes().iterator();
2857 while(attrIt.hasNext()){
2860 newAttr.setAnnotationType(newType);
2861 clonedAttr.add(newAttr);
2864 newType.setAttributes(clonedAttr);
2875 if(types != null && !types.isEmpty()){
2876 Iterator<AnnotType> typesIt = types.iterator();
2877 while(typesIt.hasNext()){
2878 if(typesIt.next().getUri().equals(uri)){
2900 for (Iterator<AnnotType> it = clonedTypes.iterator(); it.hasNext();) {
2902 if (type.
getUri().equals(changedURI)) {
2909 clonedType.setUri(changedURI);
2910 clonedType.setGroup(currentGroup);
2916 clonedTypes.add(clonedType);
2919 ArrayList<AnnotType> ancestorsOfType = currentType.getAncestorTypesAL();
2920 if(ancestorsOfType != null && !ancestorsOfType.isEmpty()){
2922 Iterator<AnnotType> ancestorsOfTypeIt = ancestorsOfType.iterator();
2923 while(ancestorsOfTypeIt.hasNext()){
2926 AnnotType currentAncestorType = ancestorsOfTypeIt.next();
2932 dbType =
cloneTypesTree(currentAncestorType,currentGroup,clonedTypes);
2936 if (!clonedTypes.contains(dbType)) {
2937 clonedTypes.add(dbType);
2947 clonedType.setAncestorType(dbType);
2951 clonedType.addAncestorType(dbType);
2971 ArrayList<AnnotType> changedTypes =
new ArrayList<AnnotType>();
2977 String[] namesArr = namesStr.split(
"/");
2978 ArrayList<String> names =
new ArrayList<String>(Arrays.asList(namesArr));
2979 int nSize = names.size();
2982 String typeName = names.remove(nSize - 1);
2984 type.setName(typeName);
2988 String nextName = nextType.getName();
2990 String prevName = names.remove(nSize - 1);
2993 String nUri = nextType.getUri();
2996 String prevUri = nUri.substring(0, nUri.lastIndexOf(
"/"));
2998 boolean foundInNewTypes =
false;
3001 Object[] params =
new Object[2];
3003 params[1] = prevUri;
3004 List tList = AppBean.getPersistenceManager().queryDB(
"AnnotType.findByUri", params);
3005 if (tList != null && !tList.isEmpty()) {
3007 nextType.setAncestorType(prevType);
3008 nextType.addAncestorType(prevType);
3011 else if (newTypes != null && !newTypes.isEmpty()) {
3012 Iterator<AnnotType> newTypesIt = newTypes.iterator();
3013 while (newTypesIt.hasNext()) {
3015 if (newType.
getUri().equals(prevUri)) {
3016 nextType.setAncestorType(newType);
3017 nextType.addAncestorType(newType);
3018 foundInNewTypes =
true;
3025 if (!foundInNewTypes) {
3027 nextType.setAncestorType(newType);
3028 nextType.addAncestorType(newType);
3029 changedTypes.add(newType);
3034 return changedTypes;
3044 EntityManager em = AppBean.getPersistenceManager().getEM();
3045 EntityTransaction transaction = em.getTransaction();
3047 transaction.begin();
3049 ArrayList<AnnotType> alreadyStored =
new ArrayList<AnnotType>();
3052 ArrayList<AnnotType> nTWA =
new ArrayList<AnnotType>();
3053 Map<String, AnnotType> nTMap =
new HashMap<String, AnnotType>();
3054 for (Iterator<AnnotType> ntIt = types.iterator(); ntIt.hasNext();) {
3056 if (type.
getId() != null) {
3057 alreadyStored.add(type);
3061 nT.setRestrictedAtt(type.getRestrictedAtt());
3062 nT.setUriInOntology(type.getUriInOntology());
3063 nT.setComment(type.getComment());
3065 nTMap.put(type.getUri(), type);
3069 ArrayList<AnnotType> mergedTypes =
new ArrayList<AnnotType>();
3070 Map<String, AnnotType> mTypesMap =
new HashMap<String, AnnotType>();
3071 for (Iterator<AnnotType> nTWAIt = nTWA.iterator(); nTWAIt.hasNext();) {
3073 if (type.
getId() != null) {
3076 type = em.merge(type);
3077 mergedTypes.add(type);
3078 mTypesMap.put(type.getUri(), type);
3082 for (Iterator<AnnotType> mIt = mergedTypes.iterator(); mIt.hasNext();) {
3084 AnnotType oType = nTMap.get(mType.getUri());
3087 if (oType == null || mType == null || mType.
getId() != null || oType.getId() != null){
3092 List<AnnotTypeAttr> aList = oType.getAttributes();
3093 for (Iterator<AnnotTypeAttr> aIt = aList.iterator(); aIt.hasNext();) {
3095 AnnotType aTAAT = aTA.getAttributeType();
3096 if (aTAAT != null) {
3098 AnnotType rType = mTypesMap.get(aTAAT.getUri());
3099 if (rType == null) {
3102 aTA.setAttributeType(rType);
3105 aTA.setAnnotationType(mTypesMap.get(aTA.getAnnotationType().getUri()));
3107 mType.setAttributes(
new ArrayList<AnnotTypeAttr>(aList));
3110 if (oType.getAncestorType() != null) {
3112 AnnotType rType = mTypesMap.get(oType.getAncestorType().getUri());
3113 if (rType == null) {
3114 rType =
queryType(oType.getAncestorType().getUri(), em);
3116 mType.setAncestorType(rType);
3120 ArrayList<AnnotType> newAncestors =
new ArrayList<AnnotType>();
3121 if (oType.getAncestorTypes() != null) {
3122 for (Iterator<AnnotType> ancIt = oType.getAncestorTypes().iterator(); ancIt.hasNext();) {
3124 AnnotType mAnc = mTypesMap.get(ancType.getUri());
3129 if (mAnc != null && (ancType.
getId() != null || mAnc.getId() != null)) {
3132 newAncestors.add(mAnc);
3135 mType.setAncestorTypes(newAncestors);
3141 transaction.commit();
3142 mergedTypes.addAll(alreadyStored);
3144 types.addAll(mergedTypes);
3146 }
catch (Exception e) {
3147 transaction.rollback();
3149 String msg =
"Persisting of types of annotations failed.";
3150 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg, e);
3172 Object[] params =
new Object[2];
3175 Query q = em.createNamedQuery(
"AnnotType.findByUri");
3176 for (
int p = 0; p < params.length; p = p + 2) {
3177 q.setParameter((String) params[p], params[p + 1]);
3179 List aList = q.getResultList();
3180 if (aList != null && !aList.isEmpty()) {
3184 String msg =
"New type of annotation was not found.";
3185 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
3187 throw new RuntimeException(
"New type not found!");
3200 ArrayList<Suggestion> result =
new ArrayList<Suggestion>();
3203 Object[] params = {
"sourceDocId",documentId,
"minCon",minimalConfidence};
3204 @SuppressWarnings(
"unchecked")
3205 List<Suggestion> suggestionList = AppBean.getPersistenceManager().queryDB(
"Suggestion.findForAlternatives",params);
3218 ArrayList<Suggestion> result =
new ArrayList<Suggestion>();
3221 Object[] params = {
"sourceDocId",documentId};
3222 @SuppressWarnings(
"unchecked")
3223 List<Suggestion> suggestionList = AppBean.getPersistenceManager().queryDB(
"Suggestion.findBySourceDocId",params);
3236 if(suggestionList != null && !suggestionList.isEmpty()){
3237 Iterator<Suggestion> suggestionListIt = suggestionList.iterator();
3238 while(suggestionListIt.hasNext()){
3239 Suggestion actualSug = suggestionListIt.next();
3240 List<SugBaseAttribute> originalAttributes = actualSug.getAttributes();
3241 Iterator<SugBaseAttribute> attrIt = originalAttributes.iterator();
3242 ArrayList<SugBaseAttribute> newAttributes =
new ArrayList<SugBaseAttribute>();
3243 while(attrIt.hasNext()){
3246 SugBaseAttribute newAttr = SugAttributeManager.changeAttributeInstance(attr);
3247 newAttributes.add(newAttr);
3251 if(!newAttributes.isEmpty()){
3252 originalAttributes.addAll(newAttributes);
3253 actualSug.setAttributes(
new ArrayList<SugBaseAttribute>(originalAttributes));
3256 result.addAll(suggestionList);
3267 Object[] params = {
"uri",uri,
"groupId",groupId};
3268 @SuppressWarnings(
"unchecked")
3269 List<AnnotType> types = AppBean.getPersistenceManager().queryDB(
"AnnotType.findByUriAndGroup",params);
3270 if(types == null || types.isEmpty()){
3274 return types.get(0);
3284 Object[] params = {
"uri",uri};
3285 @SuppressWarnings(
"unchecked")
3286 List<AnnotType> types = AppBean.getPersistenceManager().queryDB(
"AnnotType.findByUri",params);
3287 if(types == null || types.isEmpty()){
3291 return types.get(0);
3301 ArrayList<SugLinkedAttribute> result =
new ArrayList<SugLinkedAttribute>();
3302 Object[] params = {
"linked",suggId};
3303 @SuppressWarnings(
"unchecked")
3304 List<SugLinkedAttribute> attr = AppBean.getPersistenceManager().queryDB(
"SuggestionAttribute.findByLinked",params);
3305 if(attr != null && !attr.isEmpty()){
3306 result.addAll(attr);
3319 ArrayList<SugNestedAttribute> result =
new ArrayList<SugNestedAttribute>();
3320 Object[] params = {
"nested",suggId};
3321 @SuppressWarnings(
"unchecked")
3322 List<SugNestedAttribute> attr = AppBean.getPersistenceManager().queryDB(
"SuggestionAttribute.findByNested",params);
3323 if(attr != null && !attr.isEmpty()){
3324 result.addAll(attr);
3336 if(feedback != null){
3340 String msg =
"Can't save feedback to DB. Object: \n" + feedback.toString();
3341 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
3353 if(feedback != null){
3355 if(savedSuggestionF == null){
3358 String msg =
"Can't save feedback to DB. Object: \n" + feedback.toString();
3359 Logger.getLogger(SuggestionManager.class.getName()).log(Level.SEVERE, msg);
3372 ArrayList<SuggestionFeedback> result =
new ArrayList<SuggestionFeedback>();
3374 Object[] params = {
"groupId",groupId,
"docId",documentId};
3375 @SuppressWarnings(
"unchecked")
3376 List<SuggestionFeedback> feedbackList = AppBean.getPersistenceManager().queryDB(
"SuggestionFeedback.findByDoc",params);
3377 if(feedbackList != null && !feedbackList.isEmpty()){
3378 result.addAll(feedbackList);
3391 Object[] params = {
"annotationId",annotId};
3392 @SuppressWarnings(
"unchecked")
3393 List<SuggestionFeedback> feedbackList = AppBean.getPersistenceManager().queryDB(
"SuggestionFeedback.findByAnnot",params);
3394 if(feedbackList != null && !feedbackList.isEmpty()){
3395 return feedbackList.get(0);
3410 ArrayList<SuggestionFeedback> result =
new ArrayList<SuggestionFeedback>();
3412 Object[] params = {
"groupId",groupId,
"docId",documentId};
3413 @SuppressWarnings(
"unchecked")
3414 List<SuggestionFeedback> feedbackList = AppBean.getPersistenceManager().queryDB(
"SuggestionFeedback.findByDocNeg",params);
3415 if(feedbackList != null && !feedbackList.isEmpty()){
3416 result.addAll(feedbackList);
3430 Object[] params = {
"suggestionId",suggestionId,
"groupId",groupId};
3431 @SuppressWarnings(
"unchecked")
3432 List<SuggestionFeedback> feedbackList = AppBean.getPersistenceManager().queryDB(
"SuggestionFeedback.findBySuggestionId",params);
3433 if(feedbackList != null && !feedbackList.isEmpty()){
3434 return feedbackList.get(0);
3446 Object[] params = {
"id",
id};
3447 @SuppressWarnings(
"unchecked")
3448 List<Suggestion> suggestionList = AppBean.getPersistenceManager().queryDB(
"Suggestion.findById",params);
3449 if(suggestionList != null && !suggestionList.isEmpty()){
3450 return suggestionList.get(0);
3479 AppBean.getLockMaster().getSuggestionLock(documentId).unlockForChange();
3493 || requestInfo.getResyncDocContent() != null){
3547 if(request.
getFlier().getEditedAnnotations() != null
3548 && !request.
getFlier().getEditedAnnotations().isEmpty()){
3562 if(request.
getFlier().getRemovedAnnotations() != null
3563 && !request.
getFlier().getRemovedAnnotations().isEmpty()){
3577 if(request.
getFlier().getAddedAnnotations() != null
3578 && !request.
getFlier().getAddedAnnotations().isEmpty()){
3595 String result = source;
3596 if (result != null) {
3597 result = result.replace(
"\\",
"\\\\");
3598 result = result.replace(
"\"",
"\\\"");
3599 result = result.replace(
"\n",
" ");
3600 result = result.replace(
"\t",
" ");
SuggestionManager(RequestInfo request)
void updateDocument(RequestInfo request, ArrayList< Suggestion > oldSuggestions, ArrayList< Suggestion > addedSuggestions, ArrayList< Suggestion > changedSuggestions, ArrayList< AnnotType > newTypes)
ArrayList< SugLinkedAttribute > getLinkedSugAttrsByLink(Integer suggId)
List< AnnotTypeAttr > getAttributes()
static void processSugAttributes(List< Suggestion > suggestionList, ArrayList< Suggestion > result)
static ArrayList< SuggestionFragment > fragToSuggFrag(ArrayList< Fragment > fragments, Suggestion reference)
void insertNewSuggestions(ArrayList< Suggestion > newSuggestions, ArrayList< Suggestion > oldSuggestions, ArrayList< Suggestion > addedSugg, ArrayList< Suggestion > changedSugg)
static LockMaster getLockMaster()
ArrayList< SuggestionLogEntry > refuseOtherSugFromFragments(RequestInfo request)
void feedbackChangeRef(ArrayList< Suggestion > list, Suggestion sgFromList, ArrayList< Suggestion > modified, SuggestionFeedback fb, ArrayList< Suggestion > removedSuggestions)
boolean equals(Object obj)
static String changeGroupInUri(String uri, Integer groupId)
void setConfidenceToAllNested(Suggestion sg, Integer confidence, ArrayList< Suggestion > changedSuggestions)
AnnotDocument getSyncDocument()
Utility functions for document linearization.
synchronized boolean init()
void unlockDocForChange(Integer documentId)
void annotationsAddChange(RequestInfo request)
static final int LOG_LEVEL_ALL_ERRORS
Attribute manager provides a way how to create new attributes for prupose of suggestion.
static final int NOT_USABLE_CONFIDENCE
String makeClientMessage(String suggestionToAddM, String suggestionToRemoveM)
void updateDocument(RequestInfo request)
boolean isAnnotAdded(RequestInfo request)
Class representing attribute of type of annotation.
ArrayList< TextModification > getTextModifications()
static AnnotType getAnnotTypeFromDB(Integer groupId, String uri)
Suggestion getSuggestion()
String printSuggestionsDiff(EditorSession session, ArrayList< Suggestion > modifiedSuggestions, ArrayList< AnnotType > newTypes)
Boolean isSuggFragmentChanged()
static Suggestion getSuggestionFromDB(Integer id)
String filterByClientCache(EditorSession session, ArrayList< Suggestion > shouldHave, ArrayList< Suggestion > changedSuggestions)
static boolean updateSuggestion(Suggestion suggestion, RequestInfo request)
ArrayList< Suggestion > cutRefusedSuggLinks(ArrayList< Suggestion > userSuggestions, ArrayList< Suggestion > refusedSuggestions)
static boolean isSecCommandEmpty()
Class for manipulation with alternatives of suggestions.
void rejectSuggestions(RequestInfo request, ArrayList< SuggestionLogEntry > skipSugs, ArrayList< SuggestionLogEntry > noAlternatives)
int compare(SuggestionFragment frag1, SuggestionFragment frag2)
static void filtrateSuggestions(RequestInfo requestInfo, EditorSession session, ArrayList< Suggestion > userSuggestions)
Class representing annotated copy of document.
boolean contentEquals(Object obj)
Annotation getNestedInAnnot()
Class representing attribute of type NestedAnnotation for peupose of suggestion.
static void initReqTypesFromRemote(SECAPIConn conn, RequestInfo requestInfo)
static final int LOG_LEVEL_SERVER_INTERNAL_ERRORS
AnnotType getAncestorType()
ArrayList< Suggestion > findSuggestions(ArrayList< Suggestion > suggestions, Suggestion suggestion)
Singleton for storing global variables.
static final int MINIMAL_FILTER_CONFIDENCE
static AnnotType getAnnotTypeFromDB(String uri)
static String getBaseTypeUri()
static void filtrateByFragments(EditorSession session, ArrayList< Suggestion > userSuggestions)
static AnnotType queryType(String uri, EntityManager em)
static final int INITIAL_CONFIDENCE
boolean isNegativeFeedback(RequestInfo request)
Suggestion getNestedSuggestion()
Class providing access to available matchers.
static void loadTypeDefsFromDB()
Suggestion findSuggestion(ArrayList< Suggestion > suggestions, Suggestion suggestion)
static void persistFeedback(SuggestionFeedback feedback)
static final int REFUSED_AUTOMATICALLY
static ArrayList< Suggestion > getNestedSuggFromToDelete(ArrayList< Suggestion > inputSuggs, ArrayList< Suggestion > suggsToDelete)
static void updateFeedback(SuggestionFeedback feedback)
Class representing attribute of suggestion.
boolean isAnnotChange(RequestInfo request)
Class representing suggested annotation fragment.
Class holds pair of suggestion and corresponding anntation.
boolean haveLinkOn(Suggestion suggestion, Suggestion linkedSuggestion)
Interface for call of SEC API as external program (deamon)
static ArrayList< SuggestionFragment > getLinearized(Document doc, ArrayList< SuggestionFragment > fragments)
Suggested annotation with informations about suggestion.
static final int MINIMAL_CONFIDENCE
Class representing user group.
String getSuggestionsFromSECAPI(RequestInfo parRequestInfo, String doc, String uri, boolean useAlternatives, ArrayList< Suggestion > validSuggestions)
static boolean hasAttributeRightInstance(SugBaseAttribute attr)
String getDeleteMessagesString(ArrayList< Integer > suggestions)
boolean isSuggestionInFeedback(ArrayList< SuggestionFeedback > feedbackList, Suggestion searchedSugg)
static AnnotType cloneTypesTree(AnnotType currentType, UserGroup currentGroup, ArrayList< AnnotType > clonedTypes)
static void cloneTypeAttributes(AnnotType referenceType, AnnotType newType)
static void checkTypes(EditorSession session, ArrayList< Suggestion > suggestions, ArrayList< AnnotType > newTypes, boolean solveAtribute)
static ArrayList< Suggestion > getAllDependencies(Suggestion suggestion)
ArrayList< Suggestion > getAllLinkedSugg(Suggestion suggestion)
Methods for translating output from SEC API to the Suggestion objects.
static final boolean SEC_API_SUGGESTIONS
Suggestion findSuggInArray(Integer id, ArrayList< Suggestion > list)
ArrayList< SuggestionLogEntry > getOrigRefusedSuggestions()
ArrayList< Suggestion > getAlternativesRequestedFor()
static boolean isTypeInGroups(AnnotType annotType, RequestInfo requestInfo)
ArrayList< Suggestion > updateNegativeFeedback(RequestInfo request, ArrayList< SuggestionLogEntry > skipSugs, ArrayList< SuggestionLogEntry > noAlternatives)
Annotation getAnnotation()
Class provides offerining of suggestions with usage of local knowledge repository.
static boolean isInFragment(Document doc, Suggestion sugg, SuggestionFragment linFragment)
Suggestion getNestedInSuggestion()
List< SuggestionFragment > getFragments()
static boolean isAnnotTypeInArray(ArrayList< AnnotType > types, String uri)
String getAnnotatedText()
ArrayList< SuggestionFragment > getFragmentsAL()
Class for creating of requested type definition for SEC API.
ArrayList< Fragment > getSuggestionsFr()
boolean isDocUpdate(RequestInfo request)
Class for XML document fragment.
static final int LOG_LEVEL
static ArrayList< SecApiReqTypeDef > getReqTypeDefinitions()
Class representing type of annotation.
Compare class using Levenshtein approximate string matching method.
EditorSession getSession()
static String EscapeForSecApi(String source)
Class representing attribute of type AnnotationLink for prupose of suggestion.
ArrayList< Suggestion > updateSuggestionsFragments(ArrayList< Suggestion > suggestions, RequestInfo request, ArrayList< Suggestion > changedSugg)
static boolean checkException(JSONObject jsonData)
static String printTypes(RequestInfo requestInfo, EditorSession session, ArrayList< AnnotType > newTypes)
String annotationsDelete(RequestInfo request)
String getSuggestionsFromRemoteSECAPI(RequestInfo parRequestInfo, String doc, String uri, boolean useAlternatives, ArrayList< Suggestion > validSuggestions)
static PersistM getPersistenceManager()
Class consisting of traversing method and compare method.
static Suggestion getSuggestionFromList(Integer suggestionId, List< Suggestion > list)
static AnnotType cloneType(AnnotType referenceType)
Exact XPath node iterator.
UserGroup getDefaultGroup()
boolean isPositiveFeedback(RequestInfo request)
static ArrayList< SuggestionFeedback > getFeedbackFromDB(Integer documentId, Integer groupId)
static final Boolean USE_REMOTE_SEC_API
static final int LOG_LEVEL_SERVER_ERRORS
static final int PROTOCOL_LOD_V1_1
boolean isAnnotDelete(RequestInfo request)
static final int PROTOCOL_LOD_V2
Node iterator which is gradually unnesting.
static Suggestion updateSuggNegativeFeedback(RequestInfo request, Integer groupId, int refusedSuggID, boolean processAlternatives)
static SuggestionFeedback getFeedbackByAnnot(Integer annotId)
ArrayList< SuggestionLogEntry > getConfirmedSuggestions()
Class implementing functions for communication with remote SEC API.
ArrayList< Suggestion > getSuggestionWithoutFeedback(ArrayList< Suggestion > list, ArrayList< Suggestion > modified)
AnnotDocument getSyncDocument()
static final int REFUSED_CONFIDENCE
static SuggestionFeedback getFeedbackSFromDB(Integer suggestionId, Integer groupId)
static String createSecApiTypesRequest()
Class for matcher consisting of comparator and node iterator.
Processed informations about client request.
static void sendToOthers(RequestInfo requestInfo, String message)
int compare(Suggestion s1, Suggestion s2)
Class representing suggestion of annotation.
boolean isSuggestionsRequest(RequestInfo request)
static final int CONFIRMED_CONFIDENCE
static boolean persistTypes(ArrayList< AnnotType > types)
static ArrayList< Suggestion > addAllDependencies(ArrayList< Suggestion > filteredSuggestions, ArrayList< Suggestion > nonFilteredSuggestion)
static void filtrateByConfidence(Integer minimalConfidence, ArrayList< Suggestion > userSuggestions)
static ArrayList< AnnotType > breakdownType(AnnotType type, RequestInfo requestInfo, ArrayList< AnnotType > newTypes)
void compareFragments(ArrayList< Suggestion > suggestions, ArrayList< Suggestion > changedSuggestions)
ArrayList< SuggestionFeedback > getNegFeedbackFromDB(Integer documentId, Integer groupId)
Informations about client session.
Represents database entitiy with suggestion feedback. feedback.
ArrayList< SuggestionLogEntry > getRefusedSuggestions()
static final String MODULE_NAME
Utility class (manipulates RFC 3339 dates)
Class representing annotated fragment.
static String disambiguate
static void initReqTypes()
Class representing annotation.
ArrayList< Suggestion > filtrateRefusedSugg(RequestInfo request, ArrayList< Suggestion > docSuggestions)
ArrayList< Suggestion > getSuggestionsForAlternatives(Integer documentId, int minimalConfidence)
ArrayList< SugNestedAttribute > getNestedSugAttrsByNested(Integer suggId)
static AnnotType getTypeWithSameURI(List< AnnotType > list, String uri)
ArrayList< Suggestion > getAffectedForDelete(ArrayList< Annotation > removedAnnot)
AnnotSugPair getPairByAnnot(ArrayList< AnnotSugPair > pairs, Annotation annot)
void lockDocForChange(Integer documentId)
static String getSuggestionsXMLFromJSON(String responseData)
String getAddMessagesString(ArrayList< Suggestion > suggestions)
static void filtrateByType(EditorSession session, ArrayList< Suggestion > userSuggestions)
Class which implements Comparator to sort arrayList of SuggestionFragment alphabetically.
static ArrayList< Integer > findSeparators(String doc)
The object implements comparator of Alternative objects that are compared by confidence (from highest...
static SuggestionSource sourceOfSuggestions(String document)
static String createSecApiSuggestionsRequest(String doc, String uri, boolean useAlternatives)
static ArrayList< Suggestion > getSuggestionsFromDB(Integer documentId)
String getSuggestions(RequestInfo request)
void getNewClientCache(ArrayList< Suggestion > addedSugg, ArrayList< Integer > deletedSugg, ArrayList< Integer > actualCache)