This application was developed to process survey responses, particularly for handling Chinese text-based multiple-choice questions from platforms like Wenjuanxing. The system outputs responses as raw text strings, which need to be parsed for statistical analysis using binary or multinomial logistic regression models. The core functionality involves string comparison and classificasion.
The key component of this implementation is the IndexOf method for string comparision.
namespace TextAnalyzer
{
public class MultiChoiceClassifier
{
private int optionCount, responseCount;
public int totalOptions, totalResponses;
public string[] searchTerms;
public string[] responseData;
public void LoadSearchTerms()
{
searchTerms = new string[20];
for (int i = 0; i < totalOptions; i++)
{
searchTerms[i] = Console.ReadLine();
}
}
public void LoadResponses()
{
responseData = new string[1000];
for (int i = 0; i < totalResponses; i++)
{
responseData[i] = Console.ReadLine();
}
}
public void ClassifyMultipleChoice()
{
Console.WriteLine("Classification Results:");
for (int r = 0; r < totalResponses; r++)
{
for (int t = 0; t < totalOptions; t++)
{
var position = responseData[r].IndexOf(searchTerms[t]);
if (position != -1)
Console.WriteLine(t);
}
}
}
}
public class BinaryClassifier
{
private int termCount, responseCount;
public int totalTerms, totalResponses;
public string[] searchTerms;
public string[] responses;
public void LoadTerms()
{
searchTerms = new string[20];
for (int i = 0; i < totalTerms; i++)
searchTerms[i] = Console.ReadLine();
}
public void LoadResponses()
{
responses = new string[1000];
for (int i = 0; i < totalResponses; i++)
responses[i] = Console.ReadLine();
}
public void ClassifyBinary()
{
for (int t = 0; t < totalTerms; t++)
{
Console.WriteLine("Set {0}", t + 1);
for (int r = 0; r < totalResponses; r++)
{
var position = responses[r].IndexOf(searchTerms[t]);
Console.WriteLine(position != -1 ? "1" : "0");
}
}
}
}
internal class SurveyAnalyzer
{
static void Main(string[] args)
{
int analysisType;
BinaryClassifier binaryClassifier = new BinaryClassifier();
MultiChoiceClassifier multiClassifier = new MultiChoiceClassifier();
Console.WriteLine("Select analysis type: Binary logistic (1) or Multinomial");
analysisType = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter total number of records:");
if (analysisType == 1)
{
binaryClassifier.totalResponses = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number of search terms:");
binaryClassifier.totalTerms = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter search terms:");
binaryClassifier.LoadTerms();
Console.WriteLine("Enter response data:");
binaryClassifier.LoadResponses();
binaryClassifier.ClassifyBinary();
}
else
{
multiClassifier.totalResponses = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number of search terms:");
multiClassifier.totalOptions = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter search terms:");
multiClassifier.LoadSearchTerms();
Console.WriteLine("Enter response data:");
multiClassifier.LoadResponses();
multiClassifier.ClassifyMultipleChoice();
}
Console.ReadKey();
}
}
Sample Output:
Select analysis type: Binary logistic (1) or Multinomial
1
Enter total number of records:
6
Enter number of search terms:
3
Enter search terms:
Agree
Disagree
Uncertain
Enter response data:
Agree
Disagree
True
False
Uncertain
Maybe Agree
Set 1
1
0
0
0
0
1
Set 2
0
0
0
1
0
0
Set 3
0
0
0
0
1
0
The application can also handle multiple-choice classification. While the main function could be improved in terms of code structure, it effectively solves the problem of text classification for survey data.
P.C# was chosen for this implementation because Visual Studio supports Chinese input/output, unlike other development environments that had limitations with non-English characters.
Researchers conducting SPSS analysis can directly use this tool to simplify their classification process.