Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1551 | Anzahl registrierter User: 1841 | Besucher online: 20
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Stopwörter in einem Text entfernen (Englisch)


Autor: Jan Welker
Sprache: C#
Bewertung:
noch nicht bewertet
Anzahl der Aufrufe: 2993
  
Kick it on dotnet-kicks.de  

Beschreibung:

Bei der Volltextsuche stören häufig Wörter wie "most" oder "each", diese können mit dieser Funktion entfernt werden.

benötigte Namespaces:
System.Collections
System.Text.RegularExpressions


Abgelegt unter: Stopwort, Stopwörter, Suche, Volltextsuche.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// <summary>
/// Diese Funktion entfernt alle englischen Stopworte aus dem übergebenen String.
/// </summary>
/// <param name="Orginaltext">der Orginaltext</param>
/// <returns>der Orginaltext ohne Stopworte und ohne satz- und sonderzeichen</returns>
private string StoppwörterEntfernen(string orginaltext)
{
    // dieses Array enthällt alle Stoppwörter
    string[] arrStopwörter = { "about", "above", "across", "after", "afterwards", "again", "against", "albeit", "all", "almost", "alone", "along", "already", "also", "although", "always", "among", "amongst", "and", "another", "any", "anyhow", "anyone", "anything", "anywhere", "are", "around", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "both", "but", "cannot", "comprises", "corresponding", "could", "described", "desired", "does", "down", "during", "each", "either", "else", "elsewhere", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "first", "for", "former", "formerly", "from", "further", "generally", "had", "has", "have", "having", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "indeed", "into", "its", "itself", "last", "latter", "latterly", "least", "less", "many", "may", "means", "meanwhile", "might", "more", "moreover", "most", "mostly", "much", "must", "myself", "namely", "neither", "never", "nevertheless", "next", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "off", "often", "once", "one", "only", "onto", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own", "particularly", "per", "perhaps", "preferably", "preferred", "present", "rather", "relatively", "respectively", "said", "same", "seem", "seemed", "seeming", "seems", "several", "she", "should", "since", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "sitable", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefor", "therefore", "therein", "thereof", "thereto", "thereupon", "these", "they", "this", "those", "though", "through", "throughout", "thru", "thus", "together", "too", "toward", "towards", "under", "until", "upon", "use", "various", "very", "was", "well", "were", "what", "whatever", "whatsoever", "when", "whence", "whenever", "whensoever", "where", "whereafter", "whereas", "whereat", "whereby", "wherefrom", "wherein", "whereinto", "whereof", "whereon", "whereto", "whereunto", "whereupon", "wherever", "wherewith", "whether", "which", "whichever", "whichsoever", "while", "whilst", "whither", "who", "whoever", "whole", "whom", "whomever", "whomsoever", "whose", "whosoever", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves" };

    // Dictionary anlegen
    Dictionary<string, bool> dicStöppwörter = new Dictionary<string, bool>();
    
    // Dictionary füllen
    foreach (string stoppwort in arrStopwörter)
        dicStöppwörter.Add(stoppwort, true);
 
    // String Array aus dem Orginaltext anlegen, alle "nicht - Wortzeichen" werden entfernt
    string[] arrOrginaltext = Regex.Split(orginaltext, @"\W+");

    // Stringbuilder für den Rückgabewert anlegen
    StringBuilder rückgabe = new StringBuilder();

    // nur alle nicht-Stoppwörter werden an den Rückgabestring angehängt
    foreach (string wort in arrOrginaltext)
        if (!dicStöppwörter.ContainsKey(wort.ToLower()))
            rückgabe.Append(wort + " ");

    return rückgabe.ToString();
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.