Buon pomeriggio!
Sto affrontando un problema con questa maledettissima classe .
Per un progettino universitario ho bisogno di controllare che una certa stringa sia presente in un'altra. Nulla di più semplice, chiaro. Tuttavia io dovrei controllare che la mia stringa contenga in qualsiasi punto un'altra stringa data da: miastringa1 + un massimo di 3 parole + miastringa2.
Posto un pò di codice per capire meglio.
codice:
String app = "Cancer occurs when the homeostatic balance between cell growth and cell death is disturbed. Research in cancer biology has discovered that a variety of aberrations in gene expression of anti-apoptotic, pro-apoptotic and BH3-only proteins[clarification needed] can contribute to the many forms of the disease. An example can be seen in lymphomas. The over-expression of the anti-apoptotic Bcl-2 protein in lymphocytes alone does not cause cancer. But simultaneous over-expression of Bcl-2 and the proto-oncogene myc may produce aggressive B-cell malignancies including lymphoma.[5] In follicular lymphoma, a chromosomal translocation commonly occurs between the fourteenth and the eighteenth chromosomes—t(14;18) — which places the Bcl-2 gene next to the immunoglobulin heavy chain locus. This fusion gene is deregulated, leading to the transcription of excessively high levels of Bcl-2.[6] This decreases the propensity of these cells for undergoing apoptosis.";     
                    Corpus pcorpus = Factory.newCorpus("Prova");
                    application.setCorpus(pcorpus);
                    Document pdoc = Factory.newDocument(app);                    
                    pcorpus.add(pdoc);                                        
                    application.execute();                                                            
                    pcorpus.clear();                    
                    AnnotationSet anno = pdoc.getAnnotations();
                    LinkedList <String> abner = new LinkedList <String> ();
                    LinkedList <String> verb = new LinkedList <String> ();
                    
                    for(Annotation ann : anno){
                      if(ann.getType().equalsIgnoreCase("Protein") || ann.getType().equalsIgnoreCase("DNA") || ann.getType().equalsIgnoreCase("RNA") ){
                        System.out.println("Abner string:");
                        System.out.print(pdoc.getContent().toString().substring(Integer.valueOf(ann.getStartNode().getOffset().toString()), Integer.valueOf(ann.getEndNode().getOffset().toString())));
                        abner.add(pdoc.getContent().toString().substring(Integer.valueOf(ann.getStartNode().getOffset().toString()), Integer.valueOf(ann.getEndNode().getOffset().toString())));                        
                        }
                      if(ann.getType().equalsIgnoreCase("VG")){
                          System.out.println("Verb String:");                          
                          verb.add(pdoc.getContent().toString().substring(Integer.valueOf(ann.getStartNode().getOffset().toString()), Integer.valueOf(ann.getEndNode().getOffset().toString())));
                          System.out.print(pdoc.getContent().toString().substring(Integer.valueOf(ann.getStartNode().getOffset().toString()), Integer.valueOf(ann.getEndNode().getOffset().toString())));
                        }
                      }
                    for(String a : abner){
                        for(String v : verb){
                            Scanner s = new Scanner(app).useDelimiter(a);
                            while(s.hasNext()){
                                System.out.println("Stampo: " + s.next());
                            }
                        }
In sostanza si tratta di fare del text-mining usando le API del GATE (General Architecture for Text Engeeniring). La stringa su cui fare lo scanner è la stringa app. Le due LinkedList contengono le due stringhe che dovrei cercare dentro app.
E' un pò confusionario, ma in sostanza è questo. Chiaramente i due for finali dovrebbero essere sbagliati o comunque non fanno quello che mi aspetto che facciano. Vi ringrazio in anticipo anche solo se date un'occhiata al codice.